@matheusbsbs / matheus-bagliano / commits / 46eb449cbe
Fork 0

filter-branch: update current branch when rewritten

Earlier, "git filter-branch --<options> HEAD" would not update the working tree after rewriting the branch. This commit fixes it. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Johannes Schindelin committed Oct 17, 2007 at 03:23 UTC 46eb449cbefac461659c42c4ba4b36de1959e7ca
2 files changed +18 -1
git-filter-branch.sh
+15
@@ -94,6 +94,10 @@ USAGE="[--env-filter <command>] [--tree-filter <command>] \
94
95 . git-sh-setup
96
97 +git diff-files --quiet &&
98 + git diff-index --cached --quiet HEAD ||
99 + die "Cannot rewrite branch(es) with a dirty working directory."
100 +
101 tempdir=.git-rewrite
102 filter_env=
103 filter_tree=
@@ -196,6 +200,9 @@ do
200 esac
201 done < "$tempdir"/backup-refs
202
203 +ORIG_GIT_DIR="$GIT_DIR"
204 +ORIG_GIT_WORK_TREE="$GIT_WORK_TREE"
205 +ORIG_GIT_INDEX_FILE="$GIT_INDEX_FILE"
206 export GIT_DIR GIT_WORK_TREE=.
207
208 # These refs should be updated if their heads were rewritten
@@ -413,4 +420,12 @@ echo
420 test $count -gt 0 && echo "These refs were rewritten:"
421 git show-ref | grep ^"$orig_namespace"
422
423 +unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
424 +test -z "$ORIG_GIT_DIR" || GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
425 +test -z "$ORIG_GIT_WORK_TREE" || GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
426 + export GIT_WORK_TREE
427 +test -z "$ORIG_GIT_INDEX_FILE" || GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" &&
428 + export GIT_INDEX_FILE
429 +git read-tree -u -m HEAD
430 +
431 exit $ret
t/t7003-filter-branch.sh
+3 -1
@@ -41,7 +41,9 @@ test_expect_success 'rewrite, renaming a specific file' '
41 '
42
43 test_expect_success 'test that the file was renamed' '
44 - test d = $(git show HEAD:doh)
44 + test d = $(git show HEAD:doh) &&
45 + test -f doh &&
46 + test d = $(cat doh)
47 '
48
49 git tag oldD HEAD~4