Subject: Re: [PATCH] clone: forbid --bare --separate-git-dir <dir>

From: Duy Nguyen <[email-masked]>
Date: Tue, 8 Jan 2013 21:16:50 +0700

On Sun, Jan 06, 2013 at 02:19:48AM -0800, Jonathan Nieder wrote:
> 	Unfortunately we forgot to forbid the --bare
> 	--separate-git-dir combination.  In practice, we know no one
> 	could be using --bare with --separate-git-dir because it is
> 	broken in the following way: <explanation here>.  So it is
> 	safe to make good on our mistake and forbid the combination,
> 	making the command easier to explain.
> 
> I don't know what would go in the <explanation here> blank above,
> though.  Is it possible that some people are relying on this option
> combination?

I can't say it's broken in what way. Maybe it's easier to just support
this case, it's not much work anyway. Jens, maybe squash this to your
original patch?

-- 8< --
diff --git a/builtin/clone.c b/builtin/clone.c
index 8d23a62..c8b09ad 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -375,6 +375,7 @@ static void clone_local(const char *src_repo, const char *dest_repo)
 
 static const char *junk_work_tree;
 static const char *junk_git_dir;
+static const char *junk_git_file;
 static pid_t junk_pid;
 
 static void remove_junk(void)
@@ -392,6 +393,8 @@ static void remove_junk(void)
 		remove_dir_recursively(&sb, 0);
 		strbuf_reset(&sb);
 	}
+	if (junk_git_file)
+		unlink(junk_git_file);
 }
 
 static void remove_junk_on_signal(int signo)
@@ -772,6 +775,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 
 	set_git_dir_init(git_dir, real_git_dir, 0);
 	if (real_git_dir) {
+		if (option_bare)
+			junk_git_file = git_dir;
 		git_dir = real_git_dir;
 		junk_git_dir = real_git_dir;
 	}
diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh
index 4435693..231bc8a 100755
--- a/t/t5600-clone-fail-cleanup.sh
+++ b/t/t5600-clone-fail-cleanup.sh
@@ -49,4 +49,14 @@ test_expect_success 'failed clone --separate-git-dir should not leave any direct
 	rmdir foo/.git/objects.bak
 '
 
+test_expect_success 'failed clone --separate-git-dir --bare should not leave any directories' '
+	mkdir foo/.git/objects.bak/ &&
+	mv foo/.git/objects/* foo/.git/objects.bak/ &&
+	test_must_fail git clone --bare --separate-git-dir gitdir foo baaar &&
+	test_must_fail test -e gitdir &&
+	test_must_fail test -e baaar &&
+	mv foo/.git/objects.bak/* foo/.git/objects/ &&
+	rmdir foo/.git/objects.bak
+'
+
 test_done
-- 8< --