git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Don't allow contrib/workdir/git-new-workdir to trash existing dirs

From
Shawn O. Pearce <spearce@spearce.org>
Date
Sep 6, 2007, 03:33 UTC
Message-ID
<20070906033341.GA32447@spearce.org>
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>
---
 contrib/workdir/git-new-workdir |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir
index c6e154a..2838546 100755
--- a/contrib/workdir/git-new-workdir
+++ b/contrib/workdir/git-new-workdir
@@ -48,6 +48,12 @@ then
 		"a complete repository."
 fi
 
+# don't recreate a workdir over an existing repository
+if test -e "$new_workdir"
+then
+	die "destination directory '$new_workdir' already exists."
+fi
+
 # make sure the the links use full paths
 git_dir=$(cd "$git_dir"; pwd)
 
-- 
1.5.3.1.840.g0fedbc
Message 1 of 1 in “Don't allow contrib/workdir/git-new-workdir to trash existing dirs”
  1. Don't allow contrib/workdir/git-new-workdir to trash existing dirsShawn O. Pearce, Sep 6, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.