git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Dustin Sallings <dustin@spy.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] Allow tracking branches to set up rebase by default.
Date: Sat, 10 May 2008 11:41:16 -0700	[thread overview]
Message-ID: <7vfxsq9f3n.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <1210271287-36719-1-git-send-email-dustin@spy.net> (Dustin Sallings's message of "Thu, 8 May 2008 11:28:06 -0700")

The patch is looking better.

I'd suggest further fixes like the attached patch to address the following
issues:

 - Do not ignore misconfiguration, but diagnose it.

 - die_bad_config() takes a variable name without surrounding explanatory
   text.  If you actually tested your patch and looked at the error
   message, it would have been blatantly obvious and you would have
   noticed it.  Not a good sign.

 - Test not just the success cases but failure cases; test not just
   explicitly configured cases but also default cases.

The last one is something everybody tends to forget, but is very
important.  It is human nature that anybody would eagerly want to
demonstrate what new things their shiny new toy does, but would forget to
make sure that it does not take effect when people do not want it (either
saying 'never' which you do have test, which is good, or not asking for it
by not setting the variable, which you didn't).  You'd notice that I
played lazy and added a check for only the "tracked remote" case when the
new variable is left unspecified, but you might want to add tests for
other variants.  Also I suspect that we would want to test cases where
autosetuprebase is given but autosetupmerge is not.

Another thing we might want to address is to move parsing of branch.*
configuration variables out of git_default_config().  They are unnecessary
for majority of commands that do not create new branches.  But that would
be a separate topic if we were to do so.


 config.c          |    8 +++++---
 t/t3200-branch.sh |   24 ++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/config.c b/config.c
index 7d76986..cf2bfd3 100644
--- a/config.c
+++ b/config.c
@@ -487,8 +487,10 @@ int git_default_config(const char *var, const char *value)
 		git_branch_track = git_config_bool(var, value);
 		return 0;
 	}
-	if (value && !strcmp(var, "branch.autosetuprebase")) {
-		if (!strcmp(value, "never"))
+	if (!strcmp(var, "branch.autosetuprebase")) {
+		if (!value)
+			return config_error_nonbool(var);
+		else if (!strcmp(value, "never"))
 			autorebase = AUTOREBASE_NEVER;
 		else if (!strcmp(value, "local"))
 			autorebase = AUTOREBASE_LOCAL;
@@ -497,7 +499,7 @@ int git_default_config(const char *var, const char *value)
 		else if (!strcmp(value, "always"))
 			autorebase = AUTOREBASE_ALWAYS;
 		else
-			die_bad_config("Invalid value for branch.autosetupmerge");
+			return error("Malformed value for %s", var);
 		return 0;
 	}
 
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index d11dd41..5cfeaa7 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -144,6 +144,18 @@ test_expect_success 'test tracking setup (non-wildcard, not matching)' \
      ! test "$(git config branch.my5.remote)" = local &&
      ! test "$(git config branch.my5.merge)" = refs/heads/master'
 
+test_expect_success 'detect misconfigured autosetuprebase' '
+	git config branch.autosetuprebase garbage &&
+	test_must_fail git branch
+'
+
+test_expect_success 'detect misconfigured autosetuprebase' '
+	git config --unset branch.autosetuprebase &&
+	echo "[branch] autosetuprebase" >>.git/config &&
+	test_must_fail git branch &&
+	git config --unset branch.autosetuprebase
+'
+
 test_expect_success 'test tracking setup via config' \
     'git config branch.autosetupmerge true &&
      git config remote.local.url . &&
@@ -316,4 +328,16 @@ test_expect_success 'autosetuprebase always on a tracked remote branch' '
 	test "$(git config branch.myr8.rebase)" = true
 '
 
+test_expect_success 'without autosetuprebase' '
+	git config --unset branch.autosetuprebase
+
+	git config remote.local.url . &&
+	git config remote.local.fetch refs/heads/*:refs/remotes/local/* &&
+	(git show-ref -q refs/remotes/local/master || git-fetch local) &&
+	git branch --track myr9 local/master &&
+	test "$(git config branch.myr9.remote)" = local &&
+	test "$(git config branch.myr9.merge)" = refs/heads/master &&
+	test "z$(git config branch.myr9.rebase)" = "z"
+'
+
 test_done

  reply	other threads:[~2008-05-10 18:42 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-29 20:49 [PATCH] Allow local branching to set up rebase by default Dustin Sallings
2008-04-29 21:56 ` Jay Soffian
     [not found]   ` <02471C27-C99D-43E7-BC58-50F2B86ED159@spy.net>
2008-05-07  6:01     ` Dustin Sallings
2008-05-07 15:19       ` Junio C Hamano
2008-05-07 16:22 ` Junio C Hamano
2008-05-08 17:32   ` Dustin Sallings
2008-05-08 18:23     ` Junio C Hamano
2008-05-08 18:28   ` [PATCH] Allow tracking branches " Dustin Sallings
2008-05-10 18:41     ` Junio C Hamano [this message]
2008-05-10 22:36       ` Dustin Sallings
2008-05-10 22:36       ` Dustin Sallings
2008-05-08 18:28   ` [PATCH] Doc: Mention branch.<name>.rebase applies to "git pull" Dustin Sallings

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=7vfxsq9f3n.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=dustin@spy.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).