Skip to content

Commit d4bda9b

Browse files
committed
Merge branch 'jk/filter-branch-sha256'
Code clean-up. * jk/filter-branch-sha256: filter-branch: drop $_x40 glob filter-branch: drop multiple-ancestor warning t7003: test ref rewriting explicitly
2 parents 20adca9 + 42efa12 commit d4bda9b

File tree

2 files changed

+33
-14
lines changed

2 files changed

+33
-14
lines changed

git-filter-branch.sh

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -492,14 +492,12 @@ then
492492
sha1=$(git rev-parse "$ref"^0)
493493
test -f "$workdir"/../map/$sha1 && continue
494494
ancestor=$(git rev-list --simplify-merges -1 "$ref" "$@")
495-
test "$ancestor" && echo $(map $ancestor) >> "$workdir"/../map/$sha1
495+
test "$ancestor" && echo $(map $ancestor) >"$workdir"/../map/$sha1
496496
done < "$tempdir"/heads
497497
fi
498498

499499
# Finally update the refs
500500

501-
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
502-
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
503501
echo
504502
while read ref
505503
do
@@ -519,7 +517,7 @@ do
519517
git update-ref -m "filter-branch: delete" -d "$ref" $sha1 ||
520518
die "Could not delete $ref"
521519
;;
522-
$_x40)
520+
*)
523521
echo "Ref '$ref' was rewritten"
524522
if ! git update-ref -m "filter-branch: rewrite" \
525523
"$ref" $rewritten $sha1 2>/dev/null; then
@@ -533,16 +531,6 @@ do
533531
fi
534532
fi
535533
;;
536-
*)
537-
# NEEDSWORK: possibly add -Werror, making this an error
538-
warn "WARNING: '$ref' was rewritten into multiple commits:"
539-
warn "$rewritten"
540-
warn "WARNING: Ref '$ref' points to the first one now."
541-
rewritten=$(echo "$rewritten" | head -n 1)
542-
git update-ref -m "filter-branch: rewrite to first" \
543-
"$ref" $rewritten $sha1 ||
544-
die "Could not rewrite $ref"
545-
;;
546534
esac
547535
git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 ||
548536
exit

t/t7003-filter-branch.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,4 +506,35 @@ test_expect_success 'rewrite repository including refs that point at non-commit
506506
! fgrep fatal filter-output
507507
'
508508

509+
test_expect_success 'filter-branch handles ref deletion' '
510+
git switch --orphan empty-commit &&
511+
git commit --allow-empty -m "empty commit" &&
512+
git tag empty &&
513+
git branch to-delete &&
514+
git filter-branch -f --prune-empty to-delete >out 2>&1 &&
515+
grep "to-delete.*was deleted" out &&
516+
test_must_fail git rev-parse --verify to-delete
517+
'
518+
519+
test_expect_success 'filter-branch handles ref rewrite' '
520+
git checkout empty &&
521+
test_commit to-drop &&
522+
git branch rewrite &&
523+
git filter-branch -f \
524+
--index-filter "git rm --ignore-unmatch --cached to-drop.t" \
525+
rewrite >out 2>&1 &&
526+
grep "rewrite.*was rewritten" out &&
527+
! grep -i warning out &&
528+
git diff-tree empty rewrite
529+
'
530+
531+
test_expect_success 'filter-branch handles ancestor rewrite' '
532+
test_commit to-exclude &&
533+
git branch ancestor &&
534+
git filter-branch -f ancestor -- :^to-exclude.t >out 2>&1 &&
535+
grep "ancestor.*was rewritten" out &&
536+
! grep -i warning out &&
537+
git diff-tree HEAD^ ancestor
538+
'
539+
509540
test_done

0 commit comments

Comments
 (0)