Skip to content

Commit e11343e

Browse files
committed
filter-repo: handle typechange modifications when first parent is pruned
Commit 509a624 (filter-repo: fix issue with pruning of empty commits, 2019-10-03) added code to get a new list of file changes when the first parent was pruned. However, this logic did not handle cases where one of the file modifications was a typechange. Add the necessary logic to handle that case. Signed-off-by: Elijah Newren <[email protected]>
1 parent 4f84a74 commit e11343e

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

git-filter-repo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1595,7 +1595,7 @@ class GitUtils(object):
15951595
oldmode, mode, oldhash, newhash, changetype = fileinfo.split()
15961596
if changetype == b'D':
15971597
file_changes.append(FileChange(b'D', path))
1598-
elif changetype in (b'A', b'M'):
1598+
elif changetype in (b'A', b'M', b'T'):
15991599
identifier = HASH_TO_ID.get(newhash, newhash)
16001600
file_changes.append(FileChange(b'M', path, identifier, mode))
16011601
else: # pragma: no cover

t/t9390-filter-repo.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,43 @@ test_expect_success 'degenerate merge with non-matching filenames' '
14081408
)
14091409
'
14101410

1411+
test_expect_success 'degenerate merge with typechange' '
1412+
test_create_repo degenerate_merge_with_typechange &&
1413+
(
1414+
cd degenerate_merge_with_typechange &&
1415+
1416+
touch irrelevant_file &&
1417+
git add irrelevant_file &&
1418+
git commit -m "Irrelevant, unwanted file"
1419+
git branch A &&
1420+
1421+
git checkout --orphan B &&
1422+
git reset --hard &&
1423+
echo hello >world &&
1424+
git add world &&
1425+
git commit -m "greeting" &&
1426+
echo goodbye >planet &&
1427+
git add planet &&
1428+
git commit -m "farewell" &&
1429+
1430+
git checkout A &&
1431+
git merge --allow-unrelated-histories --no-commit B &&
1432+
rm world &&
1433+
ln -s planet world &&
1434+
git add world &&
1435+
git commit &&
1436+
1437+
git filter-repo --force --path world &&
1438+
test_path_is_missing irrelevant_file &&
1439+
test_path_is_missing planet &&
1440+
echo world >expect &&
1441+
git ls-files >actual &&
1442+
test_cmp expect actual &&
1443+
1444+
test_line_count = 2 <(git log --oneline HEAD)
1445+
)
1446+
'
1447+
14111448
test_expect_success 'Filtering a blob to make it match previous version' '
14121449
test_create_repo remove_unique_bits_of_blob &&
14131450
(

0 commit comments

Comments
 (0)