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

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>

Shawn O. Pearce committed Sep 5, 2007 at 23:33 UTC ea09ea22d65d118328642e03ad23c8257304499d
1 file changed +6
contrib/workdir/git-new-workdir
+6
@@ -48,6 +48,12 @@ then
48 "a complete repository."
49 fi
50
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 +
57 # make sure the the links use full paths
58 git_dir=$(cd "$git_dir"; pwd)
59