Skip to content

Commit ea09ea2

Browse files
spearcegitster
authored andcommitted
Don't allow contrib/workdir/git-new-workdir to trash existing dirs
Recently I found that doing a sequence like the following: git-new-workdir a b ... git-new-workdir a b by accident will cause a (and now also b) to have an infinite cycle in its refs directory. This is caused by git-new-workdir trying to create the "refs" symlink over again, only during the second time it is being created within a's refs directory and is now also pointing back at a's refs. This causes confusion in git as suddenly branches are named things like "refs/refs/refs/refs/refs/refs/refs/heads/foo" instead of the more commonly accepted "refs/heads/foo". Plenty of commands start to see ambiguous ref names and others just take ages to compute. git-clone has the same safety check, so git-new-workdir should behave just like it. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6b763c4 commit ea09ea2

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

contrib/workdir/git-new-workdir

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ then
4848
"a complete repository."
4949
fi
5050

51+
# don't recreate a workdir over an existing repository
52+
if test -e "$new_workdir"
53+
then
54+
die "destination directory '$new_workdir' already exists."
55+
fi
56+
5157
# make sure the the links use full paths
5258
git_dir=$(cd "$git_dir"; pwd)
5359

0 commit comments

Comments
 (0)