]> git.ipfire.org Git - thirdparty/git.git/blobdiff - git-filter-branch.sh
Add test for git rebase --abort
[thirdparty/git.git] / git-filter-branch.sh
index 3bb2f676bde370b8667a7999ba43706dbd9b9375..49e13f0bb1ed2bcb6e85455f24dffa912927d67a 100755 (executable)
@@ -114,7 +114,6 @@ orig_namespace=refs/original/
 force=
 while :
 do
-       test $# = 0 && usage
        case "$1" in
        --)
                shift
@@ -189,6 +188,9 @@ cd "$tempdir/t" &&
 workdir="$(pwd)" ||
 die ""
 
+# Remove tempdir on exit
+trap 'cd ../..; rm -rf "$tempdir"' 0
+
 # Make sure refs/original is empty
 git for-each-ref > "$tempdir"/backup-refs
 while read sha1 type name
@@ -209,25 +211,9 @@ ORIG_GIT_INDEX_FILE="$GIT_INDEX_FILE"
 GIT_WORK_TREE=.
 export GIT_DIR GIT_WORK_TREE
 
-# These refs should be updated if their heads were rewritten
-
-git rev-parse --revs-only --symbolic "$@" |
-while read ref
-do
-       # normalize ref
-       case "$ref" in
-       HEAD)
-               ref="$(git symbolic-ref "$ref")"
-       ;;
-       refs/*)
-       ;;
-       *)
-               ref="$(git for-each-ref --format='%(refname)' |
-                       grep /"$ref")"
-       esac
-
-       git check-ref-format "$ref" && echo "$ref"
-done > "$tempdir"/heads
+# The refs should be updated if their heads were rewritten
+git rev-parse --no-flags --revs-only --symbolic-full-name --default HEAD "$@" |
+sed -e '/^^/d' >"$tempdir"/heads
 
 test -s "$tempdir"/heads ||
        die "Which ref do you want to rewrite?"
@@ -290,10 +276,11 @@ while read commit parents; do
                eval "$filter_tree" < /dev/null ||
                        die "tree filter failed: $filter_tree"
 
-               git diff-index -r $commit | cut -f 2- | tr '\n' '\000' | \
-                       xargs -0 git update-index --add --replace --remove
-               git ls-files -z --others | \
-                       xargs -0 git update-index --add --replace --remove
+               (
+                       git diff-index -r --name-only $commit
+                       git ls-files --others
+               ) |
+               git update-index --add --replace --remove --stdin
        fi
 
        eval "$filter_index" < /dev/null ||
@@ -342,7 +329,6 @@ done < "$tempdir"/heads
 
 _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"
-count=0
 echo
 while read ref
 do
@@ -380,7 +366,6 @@ do
        ;;
        esac
        git update-ref -m "filter-branch: backup" "$orig_namespace$ref" $sha1
-       count=$(($count+1))
 done < "$tempdir"/heads
 
 # TODO: This should possibly go, with the semantics that all positive given
@@ -423,9 +408,8 @@ fi
 
 cd ../..
 rm -rf "$tempdir"
-echo
-test $count -gt 0 && echo "These refs were rewritten:"
-git show-ref | grep ^"$orig_namespace"
+
+trap - 0
 
 unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
 test -z "$ORIG_GIT_DIR" || GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR