git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Nanako Shiraishi <nanako3@lavabit.com>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Jay Soffian <jaysoffian@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH] Switch receive.denyCurrentBranch to "refuse"
Date: Sat, 31 Jan 2009 17:27:45 -0800	[thread overview]
Message-ID: <7vy6wr0wvi.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <20090131095622.6117@nanako3.lavabit.com> (Nanako Shiraishi's message of "Sat, 31 Jan 2009 09:56:22 +0900")

Nanako Shiraishi <nanako3@lavabit.com> writes:

> How about doing these before the 1.7.0 release?
> ...
> What do people think?

I haven't manged to convince myself about the "git init" change (I have
the code and also I've looked at the extent of damage the change causes to
the existing test suite), but at least I think it is a sensible suggestion
to differentiate between unconfigured-wwwand-defaults-to-warn case and
configured-to-warn-so-we-warn case.  Something like this.

-- >8 --
Subject: [PATCH] receive-pack: explain what to do when push updates the current branch

This makes "git push" issue a more detailed instruction when a user pushes
into the current branch of a non-bare repository without having an
explicit configuration set to receive.denycurrentbranch.  In such a case,
it will also tell the user that the default will change to refusal in a
future version of git.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-receive-pack.c |   58 +++++++++++++++++++++++++++++++++++------------
 t/t5516-fetch-push.sh  |    6 ++--
 2 files changed, 46 insertions(+), 18 deletions(-)

diff --git a/builtin-receive-pack.c b/builtin-receive-pack.c
index 6564a97..f2c94fc 100644
--- a/builtin-receive-pack.c
+++ b/builtin-receive-pack.c
@@ -12,6 +12,7 @@
 static const char receive_pack_usage[] = "git-receive-pack <git-dir>";
 
 enum deny_action {
+	DENY_UNCONFIGURED,
 	DENY_IGNORE,
 	DENY_WARN,
 	DENY_REFUSE,
@@ -19,7 +20,7 @@ enum deny_action {
 
 static int deny_deletes = 0;
 static int deny_non_fast_forwards = 0;
-static enum deny_action deny_current_branch = DENY_WARN;
+static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
 static int receive_fsck_objects;
 static int receive_unpack_limit = -1;
 static int transfer_unpack_limit = -1;
@@ -214,6 +215,35 @@ static int is_ref_checked_out(const char *ref)
 	return !strcmp(head, ref);
 }
 
+static char *warn_unconfigured_deny_msg[] = {
+	"Updating the currently checked out branch may cause confusion,",
+	"as the index and work tree do not reflect changes that are in HEAD."
+	"As a result, you may see the changes you just pushed into it",
+	"reverted when you run 'git diff' over there, and you may want",
+	"to run 'git reset --hard' before starting to work to recover.",
+	"",
+	"You can set 'receive.denyCurrentBranch' configuration variable to",
+	"'refuse' in the repository to forbid pushing into the current branch",
+	"of it."
+	"",
+	"To allow pushing into the current branch, you can set it to 'ignore';",
+	"but this is not recommended unless you really know what you are doing.",
+	"",
+	"To squelch this message, you can set it to 'warn'.",
+	"",
+	"Note that the default will change in a future version of git",
+	"to refuse updating the currentbranch unless you have the",
+	"configuration variable set to either 'ignore' or 'warn'."
+};
+
+static void warn_unconfigured_deny(void)
+{
+	int i;
+	for (i = 0; i < ARRAY_SIZE(warn_unconfigured_deny_msg); i++)
+		warning(warn_unconfigured_deny_msg[i]);
+}
+
+
 static const char *update(struct command *cmd)
 {
 	const char *name = cmd->ref_name;
@@ -227,22 +257,20 @@ static const char *update(struct command *cmd)
 		return "funny refname";
 	}
 
-	switch (deny_current_branch) {
-	case DENY_IGNORE:
-		break;
-	case DENY_WARN:
-		if (!is_ref_checked_out(name))
+	if (is_ref_checked_out(name)) {
+		switch (deny_current_branch) {
+		case DENY_IGNORE:
 			break;
-		warning("updating the currently checked out branch; this may"
-			" cause confusion,\n"
-			"as the index and working tree do not reflect changes"
-			" that are now in HEAD.");
-		break;
-	case DENY_REFUSE:
-		if (!is_ref_checked_out(name))
+		case DENY_UNCONFIGURED:
+		case DENY_WARN:
+			warning("updating the current branch");
+			if (deny_current_branch == DENY_UNCONFIGURED)
+				warn_unconfigured_deny();
 			break;
-		error("refusing to update checked out branch: %s", name);
-		return "branch is currently checked out";
+		case DENY_REFUSE:
+			error("refusing to update checked out branch: %s", name);
+			return "branch is currently checked out";
+		}
 	}
 
 	if (!is_null_sha1(new_sha1) && !has_sha1_file(new_sha1)) {
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 4426df9..89649e7 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -492,7 +492,7 @@ test_expect_success 'warn on push to HEAD of non-bare repository' '
 		git checkout master &&
 		git config receive.denyCurrentBranch warn) &&
 	git push testrepo master 2>stderr &&
-	grep "warning.*this may cause confusion" stderr
+	grep "warning: updating the current branch" stderr
 '
 
 test_expect_success 'deny push to HEAD of non-bare repository' '
@@ -510,7 +510,7 @@ test_expect_success 'allow push to HEAD of bare repository (bare)' '
 		git config receive.denyCurrentBranch true &&
 		git config core.bare true) &&
 	git push testrepo master 2>stderr &&
-	! grep "warning.*this may cause confusion" stderr
+	! grep "warning: updating the current branch" stderr
 '
 
 test_expect_success 'allow push to HEAD of non-bare repository (config)' '
@@ -520,7 +520,7 @@ test_expect_success 'allow push to HEAD of non-bare repository (config)' '
 		git config receive.denyCurrentBranch false
 	) &&
 	git push testrepo master 2>stderr &&
-	! grep "warning.*this may cause confusion" stderr
+	! grep "warning: updating the current branch" stderr
 '
 
 test_expect_success 'fetch with branches' '
-- 
1.6.1.2.312.g5be3c

  reply	other threads:[~2009-02-01  1:29 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1233275583u.git.johannes.schindelin@gmx.de>
2009-01-30  0:34 ` [PATCH] Switch receive.denyCurrentBranch to "refuse" Johannes Schindelin
2009-01-30  1:28   ` Jay Soffian
2009-01-30  1:32   ` Asheesh Laroia
2010-04-13 16:42     ` [PATCH] Switch receive.denyCurrentBranch to &quot;refuse&quot; Dave Abrahams
2010-04-13 17:57     ` [PATCH] Switch receive.denyCurrentBranch to "refuse" Junio C Hamano
     [not found]   ` <7v4ozhd1wp.fsf@gitster.siamese.dyndns.org>
2009-01-30  2:18     ` Junio C Hamano
2009-01-30 13:24       ` Johannes Schindelin
2009-01-30 16:33         ` Jeff King
2009-01-30 16:55           ` Johannes Schindelin
2009-01-30  2:30   ` Miklos Vajna
2009-01-30 13:28     ` Johannes Schindelin
2009-02-11  0:11       ` Miklos Vajna
2009-02-11  1:04         ` Junio C Hamano
2009-01-30  2:55   ` Jeff King
2009-01-30 14:11     ` Johannes Schindelin
2009-01-30  7:17   ` Johannes Sixt
2009-01-30  7:34     ` Jeff King
2009-01-30 13:23       ` Johannes Schindelin
2009-01-30 14:35         ` Jeff King
2009-01-30 16:17   ` Jay Soffian
2009-01-30 16:28     ` Jeff King
2009-01-30 17:01     ` Johannes Schindelin
2009-01-30 18:50       ` Jay Soffian
2009-01-30 19:03         ` Johannes Schindelin
2009-01-31  0:56           ` Nanako Shiraishi
2009-02-01  1:27             ` Junio C Hamano [this message]
2009-02-01  1:39               ` Junio C Hamano
2009-02-02 12:41               ` Jeff King
2009-02-03  4:30                 ` Junio C Hamano
2009-02-03 17:45                   ` Junio C Hamano
2009-02-06 14:06                     ` Jeff King
2009-02-07  7:51                       ` Junio C Hamano
2009-02-03  8:01                 ` Junio C Hamano
2009-02-03  8:07                   ` Jeff King
2009-02-03  9:22                     ` Junio C Hamano
2009-02-01  2:06             ` Junio C Hamano
2009-02-01  3:37               ` Sam Vilain
2009-02-01 21:33                 ` Junio C Hamano
2009-02-02  7:00                   ` Sam Vilain
2009-02-02  8:32                     ` Junio C Hamano
2009-02-02 10:50                       ` Sam Vilain
2009-02-01 22:59             ` Johannes Schindelin
2009-02-01 23:56               ` 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=7vy6wr0wvi.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=jaysoffian@gmail.com \
    --cc=nanako3@lavabit.com \
    /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).