mirror of
https://github.com/git/git.git
synced 2025-12-12 20:36:24 +01:00
The recently introduced new subcommand git-last-modified(1) runs into an
error in some scenarios. It then would exit with the message:
BUG: paths remaining beyond boundary in last-modified
This seems to happens for example when criss-cross merges are involved.
In that scenario, the function diff_tree_combined() gets called.
The function diff_tree_combined() copies the `struct diff_options` from
the input `struct rev_info` to override some flags. One flag is
`recursive`, which is always set to 1. This has been the case since the
inception of this function in af3feefa1d (diff-tree -c: show a merge
commit a bit more sensibly., 2006-01-24).
This behavior is incompatible with git-last-modified(1), when called
non-recursive (which is the default).
The last-modified machinery uses a hashmap for all the paths it wants to
get the last-modified commit for. Through log_tree_commit() the callback
mark_path() is called. The diff machinery uses diff_tree_combined()
internally, and due to it's recursive behavior the callback receives
entries inside subtrees, but not the subtree entries themselves. So a
directory is never expelled from the hashmap, and the BUG() statement
gets hit.
Because there are many callers calling into diff_tree_combined(), both
directly and indirectly, we cannot simply change it's behavior.
Instead, add a flag `no_recursive_diff_tree_combined` which supresses
the behavior of diff_tree_combined() to override `recursive` and set
this flag in builtin/last-modified.c.
Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
227 lines
4.2 KiB
Bash
Executable File
227 lines
4.2 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
test_description='last-modified tests'
|
|
|
|
. ./test-lib.sh
|
|
|
|
test_expect_success 'setup' '
|
|
test_commit 1 file &&
|
|
mkdir a &&
|
|
test_commit 2 a/file &&
|
|
mkdir a/b &&
|
|
test_commit 3 a/b/file
|
|
'
|
|
|
|
test_expect_success 'cannot run last-modified on two trees' '
|
|
test_must_fail git last-modified HEAD HEAD~1
|
|
'
|
|
|
|
check_last_modified() {
|
|
local indir= &&
|
|
while test $# != 0
|
|
do
|
|
case "$1" in
|
|
-C)
|
|
indir="$2"
|
|
shift
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac &&
|
|
shift
|
|
done &&
|
|
|
|
cat >expect &&
|
|
test_when_finished "rm -f tmp.*" &&
|
|
git ${indir:+-C "$indir"} last-modified "$@" >tmp.1 &&
|
|
git name-rev --annotate-stdin --name-only --tags \
|
|
<tmp.1 >tmp.2 &&
|
|
tr '\t' ' ' <tmp.2 >actual &&
|
|
test_cmp expect actual
|
|
}
|
|
|
|
test_expect_success 'last-modified non-recursive' '
|
|
check_last_modified <<-\EOF
|
|
3 a
|
|
1 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified recursive' '
|
|
check_last_modified -r <<-\EOF
|
|
3 a/b/file
|
|
2 a/file
|
|
1 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified recursive with show-trees' '
|
|
check_last_modified -r -t <<-\EOF
|
|
3 a
|
|
3 a/b
|
|
3 a/b/file
|
|
2 a/file
|
|
1 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified non-recursive with show-trees' '
|
|
check_last_modified -t <<-\EOF
|
|
3 a
|
|
1 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified subdir' '
|
|
check_last_modified a <<-\EOF
|
|
3 a
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified subdir recursive' '
|
|
check_last_modified -r a <<-\EOF
|
|
3 a/b/file
|
|
2 a/file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified from non-HEAD commit' '
|
|
check_last_modified HEAD^ <<-\EOF
|
|
2 a
|
|
1 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified from subdir defaults to root' '
|
|
check_last_modified -C a <<-\EOF
|
|
3 a
|
|
1 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified from subdir uses relative pathspecs' '
|
|
check_last_modified -C a -r b <<-\EOF
|
|
3 a/b/file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'limit last-modified traversal by count' '
|
|
check_last_modified -1 <<-\EOF
|
|
3 a
|
|
^2 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'limit last-modified traversal by commit' '
|
|
check_last_modified HEAD~2..HEAD <<-\EOF
|
|
3 a
|
|
^1 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'only last-modified files in the current tree' '
|
|
git rm -rf a &&
|
|
git commit -m "remove a" &&
|
|
check_last_modified <<-\EOF
|
|
1 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified with subdir and criss-cross merge' '
|
|
git checkout -b branch-k1 1 &&
|
|
mkdir -p a k &&
|
|
test_commit k1 a/file2 &&
|
|
git checkout -b branch-k2 &&
|
|
test_commit k2 k/file2 &&
|
|
git checkout branch-k1 &&
|
|
test_merge km2 branch-k2 &&
|
|
test_merge km3 3 &&
|
|
check_last_modified <<-\EOF
|
|
km3 a
|
|
k2 k
|
|
1 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'cross merge boundaries in blaming' '
|
|
git checkout HEAD^0 &&
|
|
git rm -rf . &&
|
|
test_commit m1 &&
|
|
git checkout HEAD^ &&
|
|
git rm -rf . &&
|
|
test_commit m2 &&
|
|
git merge m1 &&
|
|
check_last_modified <<-\EOF
|
|
m2 m2.t
|
|
m1 m1.t
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified merge for resolved conflicts' '
|
|
git checkout HEAD^0 &&
|
|
git rm -rf . &&
|
|
test_commit c1 conflict &&
|
|
git checkout HEAD^ &&
|
|
git rm -rf . &&
|
|
test_commit c2 conflict &&
|
|
test_must_fail git merge c1 &&
|
|
test_commit resolved conflict &&
|
|
check_last_modified conflict <<-\EOF
|
|
resolved conflict
|
|
EOF
|
|
'
|
|
|
|
|
|
# Consider `file` with this content through history:
|
|
#
|
|
# A---B---B-------B---B
|
|
# \ /
|
|
# C---D
|
|
test_expect_success 'last-modified merge ignores content from branch' '
|
|
git checkout HEAD^0 &&
|
|
git rm -rf . &&
|
|
test_commit a1 file A &&
|
|
test_commit a2 file B &&
|
|
test_commit a3 file C &&
|
|
test_commit a4 file D &&
|
|
git checkout a2 &&
|
|
git merge --no-commit --no-ff a4 &&
|
|
git checkout a2 -- file &&
|
|
git merge --continue &&
|
|
check_last_modified <<-\EOF
|
|
a2 file
|
|
EOF
|
|
'
|
|
|
|
# Consider `file` with this content through history:
|
|
#
|
|
# A---B---B---C---D---B---B
|
|
# \ /
|
|
# B-------B
|
|
test_expect_success 'last-modified merge undoes changes' '
|
|
git checkout HEAD^0 &&
|
|
git rm -rf . &&
|
|
test_commit b1 file A &&
|
|
test_commit b2 file B &&
|
|
test_commit b3 file C &&
|
|
test_commit b4 file D &&
|
|
git checkout b2 &&
|
|
test_commit b5 file2 2 &&
|
|
git checkout b4 &&
|
|
git merge --no-commit --no-ff b5 &&
|
|
git checkout b2 -- file &&
|
|
git merge --continue &&
|
|
check_last_modified <<-\EOF
|
|
b5 file2
|
|
b2 file
|
|
EOF
|
|
'
|
|
|
|
test_expect_success 'last-modified complains about unknown arguments' '
|
|
test_must_fail git last-modified --foo 2>err &&
|
|
grep "unknown last-modified argument: --foo" err
|
|
'
|
|
|
|
test_done
|