git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/2] New config variable push.default
@ 2009-03-16 15:42 Finn Arne Gangstad
  2009-03-16 15:42 ` [PATCH 1/2] New config push.default to decide default behavior for push Finn Arne Gangstad
  2009-03-16 15:42 ` [PATCH 2/2] Display warning for default git push with no push.default config Finn Arne Gangstad
  0 siblings, 2 replies; 3+ messages in thread
From: Finn Arne Gangstad @ 2009-03-16 15:42 UTC (permalink / raw)
  To: git; +Cc: gitster

Add a new configuration variable push.default that decides what action
to take if you do not give "git push" any refspecs, and no refspecs
are implied by options (--all or --mirror), and no refspecs are
configured for the current remote.

Some minor rewording of error messages since last time, and split the
patch into two. Patch 1 introduces the variable with all
functionality, and patch 2 adds a warning if the default behavior is
trigged and push.default has not been configured.

Possible configuration values are:

- nothing: Do not push anything.

- tracking: Push the current branch to the branch it is tracking.  In this
  mode, push will always push to the same branch that pull would pull from.
  This functionality does not exist today.

- current: Push the current branch to a branch of the same name on the
  current remote, create it if it does not exist.  Identical to 
  "git push <remote> HEAD", but you do not have to explicitly give the remote.

- matching: The current behavior, push every branch to the current remote if
  a branch with the same name already exists there.


Finn Arne Gangstad (2):
      New config push.default to decide default behavior for push
      Display warning for default git push with no push.default config

 Documentation/RelNotes-1.6.3.txt |    7 +++
 Documentation/config.txt         |   18 +++++++++
 builtin-push.c                   |   76 +++++++++++++++++++++++++++++++++++--
 cache.h                          |    9 ++++
 config.c                         |   28 ++++++++++++++
 environment.c                    |    1 +
 6 files changed, 134 insertions(+), 5 deletions(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] New config push.default to decide default behavior for push
  2009-03-16 15:42 [PATCH v3 0/2] New config variable push.default Finn Arne Gangstad
@ 2009-03-16 15:42 ` Finn Arne Gangstad
  2009-03-16 15:42 ` [PATCH 2/2] Display warning for default git push with no push.default config Finn Arne Gangstad
  1 sibling, 0 replies; 3+ messages in thread
From: Finn Arne Gangstad @ 2009-03-16 15:42 UTC (permalink / raw)
  To: git; +Cc: gitster, Finn Arne Gangstad

When "git push" is not told what refspecs to push, it pushes all matching
branches to the current remote.  For some workflows this default is not
useful, and surprises new users.  Some have even found that this default
behaviour is too easy to trigger by accident with unwanted consequences.

Introduce a new configuration variable "push.default" that decides what
action git push should take if no refspecs are given or implied by the
command line arguments or the current remote configuration.

Possible values are:

  'nothing'  : Push nothing;
  'matching' : Current default behaviour, push all branches that already
               exist in the current remote;
  'tracking' : Push the current branch to whatever it is tracking;
  'current'  : Push the current branch to a branch of the same name,
               i.e. HEAD.

Signed-off-by: Finn Arne Gangstad <finnag@pvv.org>
---
 Documentation/config.txt |   18 +++++++++++++++
 builtin-push.c           |   53 +++++++++++++++++++++++++++++++++++++++++----
 cache.h                  |    9 +++++++
 config.c                 |   28 ++++++++++++++++++++++++
 environment.c            |    1 +
 5 files changed, 104 insertions(+), 5 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 56bd781..1a27f60 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -1170,6 +1170,24 @@ pull.octopus::
 pull.twohead::
 	The default merge strategy to use when pulling a single branch.
 
+push.default::
+	Defines the action git push should take if no refspec is given
+	on the command line, no refspec is configured in the remote, and
+	no refspec is implied by any of the options given on the command
+	line.
++
+The term `current remote` means the remote configured for the current
+branch, or `origin` if no remote is configured. `origin` is also used
+if you are not on any branch. Possible values are:
++
+* `nothing` do not push anything.
+* `matching` push all matching branches to the current remote.
+  All branches having the same name in both ends are considered to be
+  matching. This is the current default value.
+* `tracking` push the current branch to the branch it is tracking.
+* `current` push the current branch to a branch of the same name on the
+  current remote.
+
 rebase.stat::
 	Whether to show a diffstat of what changed upstream since the last
 	rebase. False by default.
diff --git a/builtin-push.c b/builtin-push.c
index 122fdcf..45fe843 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -48,6 +48,48 @@ static void set_refspecs(const char **refs, int nr)
 	}
 }
 
+static void setup_push_tracking(void)
+{
+	struct strbuf refspec = STRBUF_INIT;
+	struct branch *branch = branch_get(NULL);
+	if (!branch)
+		die("You are not currently on a branch.");
+	if (!branch->merge_nr)
+		die("The current branch %s is not tracking anything.",
+		    branch->name);
+	if (branch->merge_nr != 1)
+		die("The current branch %s is tracking multiple branches, "
+		    "refusing to push.", branch->name);
+	strbuf_addf(&refspec, "%s:%s", branch->name, branch->merge[0]->src);
+	add_refspec(refspec.buf);
+}
+
+static void setup_default_push_refspecs(void)
+{
+	git_config(git_default_config, NULL);
+	switch (push_default) {
+	case PUSH_DEFAULT_UNSPECIFIED:
+		/* fallthrough */
+
+	case PUSH_DEFAULT_MATCHING:
+		add_refspec(":");
+		break;
+
+	case PUSH_DEFAULT_TRACKING:
+		setup_push_tracking();
+		break;
+
+	case PUSH_DEFAULT_CURRENT:
+		add_refspec("HEAD");
+		break;
+
+	case PUSH_DEFAULT_NOTHING:
+		die("You didn't specify any refspecs to push, and "
+		    "push.default is \"nothing\".");
+		break;
+	}
+}
+
 static int do_push(const char *repo, int flags)
 {
 	int i, errs;
@@ -76,11 +118,12 @@ static int do_push(const char *repo, int flags)
 		return error("--all and --mirror are incompatible");
 	}
 
-	if (!refspec
-		&& !(flags & TRANSPORT_PUSH_ALL)
-		&& remote->push_refspec_nr) {
-		refspec = remote->push_refspec;
-		refspec_nr = remote->push_refspec_nr;
+	if (!refspec && !(flags & TRANSPORT_PUSH_ALL)) {
+		if (remote->push_refspec_nr) {
+			refspec = remote->push_refspec;
+			refspec_nr = remote->push_refspec_nr;
+		} else if (!(flags & TRANSPORT_PUSH_MIRROR))
+			setup_default_push_refspecs();
 	}
 	errs = 0;
 	for (i = 0; i < remote->url_nr; i++) {
diff --git a/cache.h b/cache.h
index fdc4ada..93f00a4 100644
--- a/cache.h
+++ b/cache.h
@@ -541,8 +541,17 @@ enum rebase_setup_type {
 	AUTOREBASE_ALWAYS,
 };
 
+enum push_default_type {
+	PUSH_DEFAULT_UNSPECIFIED = -1,
+	PUSH_DEFAULT_NOTHING = 0,
+	PUSH_DEFAULT_MATCHING,
+	PUSH_DEFAULT_TRACKING,
+	PUSH_DEFAULT_CURRENT,
+};
+
 extern enum branch_track git_branch_track;
 extern enum rebase_setup_type autorebase;
+extern enum push_default_type push_default;
 
 #define GIT_REPO_VERSION 0
 extern int repository_format_version;
diff --git a/config.c b/config.c
index 0c8c76f..28ac0fb 100644
--- a/config.c
+++ b/config.c
@@ -565,6 +565,31 @@ static int git_default_branch_config(const char *var, const char *value)
 	return 0;
 }
 
+static int git_default_push_config(const char *var, const char *value)
+{
+	if (!strcmp(var, "push.default")) {
+		if (!value)
+			return config_error_nonbool(var);
+		else if (!strcmp(value, "nothing"))
+			push_default = PUSH_DEFAULT_NOTHING;
+		else if (!strcmp(value, "matching"))
+			push_default = PUSH_DEFAULT_MATCHING;
+		else if (!strcmp(value, "tracking"))
+			push_default = PUSH_DEFAULT_TRACKING;
+		else if (!strcmp(value, "current"))
+			push_default = PUSH_DEFAULT_CURRENT;
+		else {
+			error("Malformed value for %s: %s", var, value);
+			return error("Must be one of nothing, matching, "
+				     "tracking or current.");
+		}		
+		return 0;
+	}
+
+	/* Add other config variables here and to Documentation/config.txt. */
+	return 0;
+}
+
 static int git_default_mailmap_config(const char *var, const char *value)
 {
 	if (!strcmp(var, "mailmap.file"))
@@ -588,6 +613,9 @@ int git_default_config(const char *var, const char *value, void *dummy)
 	if (!prefixcmp(var, "branch."))
 		return git_default_branch_config(var, value);
 
+	if (!prefixcmp(var, "push."))
+		return git_default_push_config(var, value);
+
 	if (!prefixcmp(var, "mailmap."))
 		return git_default_mailmap_config(var, value);
 
diff --git a/environment.c b/environment.c
index e278bce..4696885 100644
--- a/environment.c
+++ b/environment.c
@@ -42,6 +42,7 @@ enum safe_crlf safe_crlf = SAFE_CRLF_WARN;
 unsigned whitespace_rule_cfg = WS_DEFAULT_RULE;
 enum branch_track git_branch_track = BRANCH_TRACK_REMOTE;
 enum rebase_setup_type autorebase = AUTOREBASE_NEVER;
+enum push_default_type push_default = PUSH_DEFAULT_UNSPECIFIED;
 
 /* Parallel index stat data preload? */
 int core_preload_index = 0;
-- 
1.6.2.1.138.gc403b.dirty

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Display warning for default git push with no push.default config
  2009-03-16 15:42 [PATCH v3 0/2] New config variable push.default Finn Arne Gangstad
  2009-03-16 15:42 ` [PATCH 1/2] New config push.default to decide default behavior for push Finn Arne Gangstad
@ 2009-03-16 15:42 ` Finn Arne Gangstad
  1 sibling, 0 replies; 3+ messages in thread
From: Finn Arne Gangstad @ 2009-03-16 15:42 UTC (permalink / raw)
  To: git; +Cc: gitster, Finn Arne Gangstad

If a git push without any refspecs is attempted, display a warning.
The current default behavior is to push all matching refspecs, which
may come as a surprise to new users, so the warning shows how
push.default can be configured and what the possible values are.

Traditionalists who wish to keep the current behaviour are also told
how to configure this once and never see the warning again.

Signed-off-by: Finn Arne Gangstad <finnag@pvv.org>
---
 Documentation/RelNotes-1.6.3.txt |    7 +++++++
 builtin-push.c                   |   23 +++++++++++++++++++++++
 2 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/Documentation/RelNotes-1.6.3.txt b/Documentation/RelNotes-1.6.3.txt
index 679ad28..d961bc8 100644
--- a/Documentation/RelNotes-1.6.3.txt
+++ b/Documentation/RelNotes-1.6.3.txt
@@ -22,6 +22,13 @@ branch pointed at by its HEAD, gets a large warning.  You can choose what
 should happen upon such a push by setting the configuration variable
 receive.denyDeleteCurrent in the receiving repository.
 
+In a future release, the default of "git push" without further
+arguments may be changed. Currently, it will push all matching
+refspecs to the current remote.  A configuration variable push.default
+has been introduced to select the default behaviour.  To ease the
+transition, a big warning is issued if this is not configured and a
+git push without arguments is attempted.
+
 
 Updates since v1.6.2
 --------------------
diff --git a/builtin-push.c b/builtin-push.c
index 45fe843..c8e559f 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -64,11 +64,34 @@ static void setup_push_tracking(void)
 	add_refspec(refspec.buf);
 }
 
+static const char *warn_unconfigured_push_msg[] = {
+	"You did not specify any refspecs to push, and the current remote",
+	"has not configured any push refspecs. The default action in this",
+	"case has been to push all matching refspecs, that is, all branches",
+	"that exist both locally and remotely will be updated.",
+	"This default may change in the future.",
+	"",
+	"You can specify what action you want to take in this case, and",
+	"avoid seeing this message again, by configuring 'push.default' to:",
+	"  'nothing'  : Do not push anythig",
+	"  'matching' : Push all matching branches (the current default)",
+	"  'tracking' : Push the current branch to whatever it is tracking",
+	"  'current'  : Push the current branch"
+};
+
+static void warn_unconfigured_push(void)
+{
+	int i;
+	for (i = 0; i < ARRAY_SIZE(warn_unconfigured_push_msg); i++)
+		warning("%s", warn_unconfigured_push_msg[i]);
+}
+
 static void setup_default_push_refspecs(void)
 {
 	git_config(git_default_config, NULL);
 	switch (push_default) {
 	case PUSH_DEFAULT_UNSPECIFIED:
+		warn_unconfigured_push();
 		/* fallthrough */
 
 	case PUSH_DEFAULT_MATCHING:
-- 
1.6.2.1.138.gc403b.dirty

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-03-16 15:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-16 15:42 [PATCH v3 0/2] New config variable push.default Finn Arne Gangstad
2009-03-16 15:42 ` [PATCH 1/2] New config push.default to decide default behavior for push Finn Arne Gangstad
2009-03-16 15:42 ` [PATCH 2/2] Display warning for default git push with no push.default config Finn Arne Gangstad

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).