Skip to content

Commit 4d2a364

Browse files
szederpeff
authored andcommitted
filter-branch: deal with object name vs. pathname ambiguity in tree-filter
'git filter-branch' fails complaining about an ambiguous argument, if a tree-filter renames a path and the new pathname happens to match an existing object name. After the tree-filter has been applied, 'git filter-branch' looks for changed paths by running: git diff-index -r --name-only --ignore-submodules $commit which then, because of the lack of disambiguating double-dash, can't decide whether to treat '$commit' as revision or path and errors out. Add that disambiguating double-dash after 'git diff-index's revision argument to make sure that '$commit' is interpreted as a revision. Signed-off-by: SZEDER Gábor <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent 5cb2e16 commit 4d2a364

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

git-filter-branch.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ while read commit parents; do
319319
die "tree filter failed: $filter_tree"
320320

321321
(
322-
git diff-index -r --name-only --ignore-submodules $commit &&
322+
git diff-index -r --name-only --ignore-submodules $commit -- &&
323323
git ls-files --others
324324
) > "$tempdir"/tree-state || exit
325325
git update-index --add --replace --remove --stdin \

t/t7003-filter-branch.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,4 +418,11 @@ test_expect_success 'filter commit message without trailing newline' '
418418
test_cmp expect actual
419419
'
420420

421+
test_expect_success 'tree-filter deals with object name vs pathname ambiguity' '
422+
test_when_finished "git reset --hard original" &&
423+
ambiguous=$(git rev-list -1 HEAD) &&
424+
git filter-branch --tree-filter "mv file.t $ambiguous" HEAD^.. &&
425+
git show HEAD:$ambiguous
426+
'
427+
421428
test_done

0 commit comments

Comments
 (0)