]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jk/filter-branch-sha256'
authorJunio C Hamano <gitster@pobox.com>
Mon, 22 Mar 2021 21:00:25 +0000 (14:00 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Mar 2021 21:00:25 +0000 (14:00 -0700)
Code clean-up.

* jk/filter-branch-sha256:
  filter-branch: drop $_x40 glob
  filter-branch: drop multiple-ancestor warning
  t7003: test ref rewriting explicitly

git-filter-branch.sh
t/t7003-filter-branch.sh

index fea79646172184c630508908dd6eb61d3470074d..cb893728136be39b2cb0042feb55d6377e870659 100755 (executable)
@@ -492,14 +492,12 @@ then
                sha1=$(git rev-parse "$ref"^0)
                test -f "$workdir"/../map/$sha1 && continue
                ancestor=$(git rev-list --simplify-merges -1 "$ref" "$@")
-               test "$ancestor" && echo $(map $ancestor) >"$workdir"/../map/$sha1
+               test "$ancestor" && echo $(map $ancestor) >"$workdir"/../map/$sha1
        done < "$tempdir"/heads
 fi
 
 # Finally update the refs
 
-_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
-_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
 echo
 while read ref
 do
@@ -519,7 +517,7 @@ do
                git update-ref -m "filter-branch: delete" -d "$ref" $sha1 ||
                        die "Could not delete $ref"
        ;;
-       $_x40)
+       *)
                echo "Ref '$ref' was rewritten"
                if ! git update-ref -m "filter-branch: rewrite" \
                                        "$ref" $rewritten $sha1 2>/dev/null; then
@@ -533,16 +531,6 @@ do
                        fi
                fi
        ;;
-       *)
-               # NEEDSWORK: possibly add -Werror, making this an error
-               warn "WARNING: '$ref' was rewritten into multiple commits:"
-               warn "$rewritten"
-               warn "WARNING: Ref '$ref' points to the first one now."
-               rewritten=$(echo "$rewritten" | head -n 1)
-               git update-ref -m "filter-branch: rewrite to first" \
-                               "$ref" $rewritten $sha1 ||
-                       die "Could not rewrite $ref"
-       ;;
        esac
        git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1 ||
                 exit
index 1c556950346f0cfcf145991cea6fe34f37a300b6..1349e5b2321c802faf50aed2af7d3cfee7c27974 100755 (executable)
@@ -506,4 +506,35 @@ test_expect_success 'rewrite repository including refs that point at non-commit
        ! fgrep fatal filter-output
 '
 
+test_expect_success 'filter-branch handles ref deletion' '
+       git switch --orphan empty-commit &&
+       git commit --allow-empty -m "empty commit" &&
+       git tag empty &&
+       git branch to-delete &&
+       git filter-branch -f --prune-empty to-delete >out 2>&1 &&
+       grep "to-delete.*was deleted" out &&
+       test_must_fail git rev-parse --verify to-delete
+'
+
+test_expect_success 'filter-branch handles ref rewrite' '
+       git checkout empty &&
+       test_commit to-drop &&
+       git branch rewrite &&
+       git filter-branch -f \
+               --index-filter "git rm --ignore-unmatch --cached to-drop.t" \
+                rewrite >out 2>&1 &&
+       grep "rewrite.*was rewritten" out &&
+       ! grep -i warning out &&
+       git diff-tree empty rewrite
+'
+
+test_expect_success 'filter-branch handles ancestor rewrite' '
+       test_commit to-exclude &&
+       git branch ancestor &&
+       git filter-branch -f ancestor -- :^to-exclude.t >out 2>&1 &&
+       grep "ancestor.*was rewritten" out &&
+       ! grep -i warning out &&
+       git diff-tree HEAD^ ancestor
+'
+
 test_done