git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paul Smith <paul@mad-scientist.net>
To: git@vger.kernel.org
Subject: [PATCH] git-new-workdir: Add -f to force new-workdir in existing directory.
Date: Thu, 13 Nov 2014 14:16:53 -0500	[thread overview]
Message-ID: <1415906213.32352.43.camel@mad-scientist.net> (raw)

From: Paul Smith <paul@mad-scientist.net>
Date: Thu, 13 Nov 2014 14:01:34 -0500
Subject: [PATCH] git-new-workdir: Add -f to force new-workdir in existing directory.

Signed-off-by: Paul Smith <psmith@mad-scientist.net>
---

I have an environment I want to use new-workdir for, where the directory
I need to use is pre-created for me and I'm dropped into that directory
and I have no control over this (it's an automated build system).  The
directory is empty but git-new-workdir still is unhappy about it.  I
added a "-f" flag to allow the user to force git-new-workdir to continue
even if the directory exists.  It still bails if there's a .git
directory already, however.

 contrib/workdir/git-new-workdir | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/contrib/workdir/git-new-workdir b/contrib/workdir/git-new-workdir
index 75e8b25..a4079c1 100755
--- a/contrib/workdir/git-new-workdir
+++ b/contrib/workdir/git-new-workdir
@@ -10,11 +10,17 @@ die () {
 	exit 128
 }
 
-if test $# -lt 2 || test $# -gt 3
+if test $# -lt 2 || test $# -gt 4
 then
-	usage "$0 <repository> <new_workdir> [<branch>]"
+	usage "$0 [-f] <repository> <new_workdir> [<branch>]"
 fi
 
+force=false
+if [ x"$1" = x-f ]
+then
+    force=true
+    shift
+fi
 orig_git=$1
 new_workdir=$2
 branch=$3
@@ -51,7 +57,11 @@ fi
 # don't recreate a workdir over an existing repository
 if test -e "$new_workdir"
 then
-	die "destination directory '$new_workdir' already exists."
+	$force || die "destination directory '$new_workdir' already exists."
+	if test -e "$new_workdir/.git"
+	then
+		die "destination directory '$new_workdir/.git' already exists."
+	fi
 fi
 
 # make sure the links use full paths
-- 
2.1.3

             reply	other threads:[~2014-11-13 19:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-13 19:16 Paul Smith [this message]
2014-11-13 21:21 ` [PATCH] git-new-workdir: Add -f to force new-workdir in existing directory Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1415906213.32352.43.camel@mad-scientist.net \
    --to=paul@mad-scientist.net \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).