X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-filter-branch.sh;h=010353ad82881886b9739cc5f8de595acc9273ef;hb=1b56bc9a1545902db64b8bdce48a499900acfe0b;hp=ebf05ca600739fcb8103dcebc6b9172eebfdacca;hpb=cab31fa076253fcfafa7572c24e40f12a1e09ae3;p=git.git diff --git a/git-filter-branch.sh b/git-filter-branch.sh index ebf05ca60..010353ad8 100755 --- a/git-filter-branch.sh +++ b/git-filter-branch.sh @@ -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 @@ -210,7 +212,7 @@ GIT_WORK_TREE=. export GIT_DIR GIT_WORK_TREE # The refs should be updated if their heads were rewritten -git rev-parse --no-flags --revs-only --symbolic-full-name "$@" | +git rev-parse --no-flags --revs-only --symbolic-full-name --default HEAD "$@" | sed -e '/^^/d' >"$tempdir"/heads test -s "$tempdir"/heads || @@ -250,7 +252,16 @@ while read commit parents; do git read-tree -i -m $commit ;; *) - git read-tree -i -m $commit:"$filter_subdir" + # The commit may not have the subdirectory at all + err=$(git read-tree -i -m $commit:"$filter_subdir" 2>&1) || { + if ! git rev-parse --verify $commit:"$filter_subdir" 2>/dev/null + then + rm -f "$GIT_INDEX_FILE" + else + echo >&2 "$err" + false + fi + } esac || die "Could not initialize the index" GIT_COMMIT=$commit @@ -274,10 +285,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 '\012' '\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 || @@ -406,6 +418,8 @@ fi cd ../.. rm -rf "$tempdir" +trap - 0 + unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE test -z "$ORIG_GIT_DIR" || GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR test -z "$ORIG_GIT_WORK_TREE" || GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&