{"thread":{"id":"9796","subject":"[PATCH] Don't allow contrib/workdir/git-new-workdir to trash existing dirs","startedAt":"2007-09-06T03:33:41Z","lastAt":"2007-09-06T03:33:41Z","messageCount":1,"participants":["Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"52682","messageId":"20070906033341.GA32447@spearce.org","threadId":"9796","inReplyTo":null,"subject":"[PATCH] Don't allow contrib/workdir/git-new-workdir to trash existing dirs","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2007-09-06T03:33:41Z","receivedAt":"2007-09-06T03:33:41Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Recently I found that doing a sequence like the following:\n\n  git-new-workdir a b\n  ...\n  git-new-workdir a b\n\nby accident will cause a (and now also b) to have an infinite cycle\nin its refs directory.  This is caused by git-new-workdir trying\nto create the \"refs\" symlink over again, only during the second\ntime it is being created within a's refs directory and is now also\npointing back at a's refs.\n\nThis causes confusion in git as suddenly branches are named things\nlike \"refs/refs/refs/refs/refs/refs/refs/heads/foo\" instead of the\nmore commonly accepted \"refs/heads/foo\".  Plenty of commands start\nto see ambiguous ref names and others just take ages to compute.\n\ngit-clone has the same safety check, so git-new-workdir should\nbehave just like it.\n\nSigned-off-by: Shawn O. Pearce <spearce@spearce.org>\n---\n contrib/workdir/git-new-workdir |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir\nindex c6e154a..2838546 100755\n--- a/contrib/workdir/git-new-workdir\n+++ b/contrib/workdir/git-new-workdir\n@@ -48,6 +48,12 @@ then\n \t\t\"a complete repository.\"\n fi\n \n+# don't recreate a workdir over an existing repository\n+if test -e \"$new_workdir\"\n+then\n+\tdie \"destination directory '$new_workdir' already exists.\"\n+fi\n+\n # make sure the the links use full paths\n git_dir=$(cd \"$git_dir\"; pwd)\n \n-- \n1.5.3.1.840.g0fedbc\n"}]}