Skip to content

Commit

Permalink
filter-repo: fix tweak_commit when parent is from an unrelated history
Browse files Browse the repository at this point in the history
Signed-off-by: matejcik <[email protected]>
  • Loading branch information
matejcik committed Sep 26, 2022
1 parent fff5f43 commit b07b17f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion git-filter-repo
Original file line number Diff line number Diff line change
Expand Up @@ -3458,7 +3458,7 @@ class RepoFilter(object):
# to the new first parent
if parents and old_1st_parent != parents[0]:
commit.file_changes = GitUtils.get_file_changes(self._repo_working_dir,
ID_TO_HASH[parents[0]],
ID_TO_HASH.get(parents[0], parents[0]),
commit.original_id)
orig_file_changes = set(commit.file_changes)
self._filter_files(commit)
Expand Down
46 changes: 46 additions & 0 deletions t/t9390-filter-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,52 @@ setup_path_rename() {
)
}

setup_unrelated_histories() {
test -d unrelated_histories && return
mkdir unrelated_histories &&
test_create_repo unrelated_histories/side-repo &&
test_create_repo unrelated_histories/test-repo &&
(
cd unrelated_histories/side-repo &&
echo 1 >test_file &&
git add test_file &&
git commit -m 1 &&

echo 2 >test_file &&
git add test_file &&
git commit -m 2 &&

git tag test_tag &&
git branch some_branch
) &&
(
cd unrelated_histories/test-repo &&
echo testing >uninteresting_file &&
git add uninteresting_file &&
git commit -m test &&

git remote add side ../side-repo &&
git fetch side &&
git fetch --tags side &&
git merge side/some_branch --allow-unrelated-histories -m "merge" &&

echo 3 >test_file &&
git add test_file &&
git commit -m 3
)
}

test_expect_success 'Commits from non-root history' '
setup_unrelated_histories &&
(
git clone file://"$(pwd)"/unrelated_histories/test-repo unrelated_histories_repo &&
cd unrelated_histories_repo &&
git filter-repo --refs test_tag..HEAD --path another_file &&
git log --format=%n --name-only | sort | uniq | grep -v "^\$" >filenames &&
test_line_count = 1 filenames
)
'

test_expect_success '--path-rename sequences/tiny:sequences/small' '
setup_path_rename &&
(
Expand Down

0 comments on commit b07b17f

Please sign in to comment.