@matheusbsbs / matheus-bagliano / commits / a4661b018d
Fork 0

git-filter-branch.sh: Allow running in bare repositories

Commit 46eb449c restricted git-filter-branch to non-bare repositories unnecessarily; git-filter-branch can work on bare repositories just fine. Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Petr Baudis committed Jul 24, 2008 at 00:15 UTC a4661b018d46699fd6a9f59932e60267bae3ca2a
2 files changed +26 -14
git-filter-branch.sh
+18 -14
@@ -97,9 +97,11 @@ USAGE="[--env-filter <command>] [--tree-filter <command>] \
97 OPTIONS_SPEC=
98 . git-sh-setup
99
100 -git diff-files --quiet &&
100 +if [ "$(is_bare_repository)" = false ]; then
101 + git diff-files --quiet &&
102 git diff-index --cached --quiet HEAD -- ||
103 die "Cannot rewrite branch(es) with a dirty working directory."
104 +fi
105
106 tempdir=.git-rewrite
107 filter_env=
@@ -434,18 +436,20 @@ rm -rf "$tempdir"
436
437 trap - 0
438
437 -unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
438 -test -z "$ORIG_GIT_DIR" || {
439 - GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
440 -}
441 -test -z "$ORIG_GIT_WORK_TREE" || {
442 - GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
443 - export GIT_WORK_TREE
444 -}
445 -test -z "$ORIG_GIT_INDEX_FILE" || {
446 - GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" &&
447 - export GIT_INDEX_FILE
448 -}
449 -git read-tree -u -m HEAD
439 +if [ "$(is_bare_repository)" = false ]; then
440 + unset GIT_DIR GIT_WORK_TREE GIT_INDEX_FILE
441 + test -z "$ORIG_GIT_DIR" || {
442 + GIT_DIR="$ORIG_GIT_DIR" && export GIT_DIR
443 + }
444 + test -z "$ORIG_GIT_WORK_TREE" || {
445 + GIT_WORK_TREE="$ORIG_GIT_WORK_TREE" &&
446 + export GIT_WORK_TREE
447 + }
448 + test -z "$ORIG_GIT_INDEX_FILE" || {
449 + GIT_INDEX_FILE="$ORIG_GIT_INDEX_FILE" &&
450 + export GIT_INDEX_FILE
451 + }
452 + git read-tree -u -m HEAD
453 +fi
454
455 exit $ret
t/t7003-filter-branch.sh
+8
@@ -38,6 +38,14 @@ test_expect_success 'result is really identical' '
38 test $H = $(git rev-parse HEAD)
39 '
40
41 +test_expect_success 'rewrite bare repository identically' '
42 + (git config core.bare true && cd .git && git-filter-branch branch)
43 +'
44 +git config core.bare false
45 +test_expect_success 'result is really identical' '
46 + test $H = $(git rev-parse HEAD)
47 +'
48 +
49 test_expect_success 'rewrite, renaming a specific file' '
50 git-filter-branch -f --tree-filter "mv d doh || :" HEAD
51 '