Skip to content

Commit a4661b0

Browse files
Petr Baudisgitster
authored andcommitted
git-filter-branch.sh: Allow running in bare repositories
Commit 46eb449 restricted git-filter-branch to non-bare repositories unnecessarily; git-filter-branch can work on bare repositories just fine. Cc: Johannes Schindelin <[email protected]> Signed-off-by: Petr Baudis <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 68067ca commit a4661b0

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

git-filter-branch.sh

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ USAGE="[--env-filter <command>] [--tree-filter <command>] \
9797
OPTIONS_SPEC=
9898
. git-sh-setup
9999

100-
git diff-files --quiet &&
100+
if [ "$(is_bare_repository)" = false ]; then
101+
git diff-files --quiet &&
101102
git diff-index --cached --quiet HEAD -- ||
102103
die "Cannot rewrite branch(es) with a dirty working directory."
104+
fi
103105

104106
tempdir=.git-rewrite
105107
filter_env=
@@ -434,18 +436,20 @@ rm -rf "$tempdir"
434436

435437
trap - 0
436438

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
450454

451455
exit $ret

t/t7003-filter-branch.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ test_expect_success 'result is really identical' '
3838
test $H = $(git rev-parse HEAD)
3939
'
4040

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+
4149
test_expect_success 'rewrite, renaming a specific file' '
4250
git-filter-branch -f --tree-filter "mv d doh || :" HEAD
4351
'

0 commit comments

Comments
 (0)