[PATCH] Teach remote machinery about core.origin config variable

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <gitster@...>
Cc: <git@...>, Mark Levedahl <mlevedahl@...>
Date: Sunday, January 13, 2008 - 12:27 pm

This introduces a new configuration variable, core.origin, that
defines the name of the default remote to be used. Traditionally, this
is "origin", and could be overridden for a given branch. This change
introduces a way to redefine the default as desired and have that honored
regardless of the currently checked out head (e.g., core.origin is
used when on a detached head or any other non-tracking branch).

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
 Documentation/config.txt |    6 ++++++
 git-parse-remote.sh      |    5 +++--
 remote.c                 |   11 ++++++++++-
 3 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index df091d1..b7241cf 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -291,6 +291,12 @@ core.editor::
 	`GIT_EDITOR` environment, `core.editor`, `VISUAL` and
 	`EDITOR` environment variables and then finally `vi`.
 
+core.origin::
+	The name of the remote used by default for fetch / pull. If unset,
+	origin is assumed. This value is used whenever the current branch
+	has no corresponding branch.<name>.remote, such as when working on
+	a detached head.
+
 core.pager::
 	The command that git will use to paginate output.  Can be overridden
 	with the `GIT_PAGER` environment variable.
diff --git a/git-parse-remote.sh b/git-parse-remote.sh
index 695a409..c7ac7c7 100755
--- a/git-parse-remote.sh
+++ b/git-parse-remote.sh
@@ -56,8 +56,9 @@ get_remote_url () {
 
 get_default_remote () {
 	curr_branch=$(git symbolic-ref -q HEAD | sed -e 's|^refs/heads/||')
-	origin=$(git config --get "branch.$curr_branch.remote")
-	echo ${origin:-origin}
+	git config --get "branch.$curr_branch.remote" ||
+	git config --get "core.origin" ||
+	echo origin
 }
 
 get_remote_default_refs_for_push () {
diff --git a/remote.c b/remote.c
index 0e00680..302d499 100644
--- a/remote.c
+++ b/remote.c
@@ -10,6 +10,7 @@ static int allocated_branches;
 
 static struct branch *current_branch;
 static const char *default_remote_name;
+static const char *core_origin;
 
 #define BUF_SIZE (2048)
 static char buffer[BUF_SIZE];
@@ -233,6 +234,11 @@ static int handle_config(const char *key, const char *value)
 			add_merge(branch, xstrdup(value));
 		return 0;
 	}
+	if (!strcmp(key, "core.origin")) {
+		if (value)
+			core_origin = xstrdup(value);
+		return 0;
+	}
 	if (prefixcmp(key,  "remote."))
 		return 0;
 	name = key + 7;
@@ -291,7 +297,6 @@ static void read_config(void)
 	int flag;
 	if (default_remote_name) // did this already
 		return;
-	default_remote_name = xstrdup("origin");
 	current_branch = NULL;
 	head_ref = resolve_ref("HEAD", sha1, 0, &flag);
 	if (head_ref && (flag & REF_ISSYMREF) &&
@@ -300,6 +305,10 @@ static void read_config(void)
 			make_branch(head_ref + strlen("refs/heads/"), 0);
 	}
 	git_config(handle_config);
+	if (!default_remote_name) {
+		default_remote_name = core_origin ?
+		core_origin : xstrdup("origin");
+	}
 }
 
 struct refspec *parse_ref_spec(int nr_refspec, const char **refspec)
-- 
1.5.4.rc3.14.gc50f

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH] Teach remote machinery about remotes.default con..., Johannes Schindelin, (Sun Jan 13, 5:27 pm)
What's not in 'master' but should be, Junio C Hamano, (Fri Jan 18, 5:41 am)
Re: What's not in 'master' but should be, Johannes Schindelin, (Fri Jan 18, 2:28 pm)
Re: [PATCH] http-push: fix webdav lock leak., Grégoire Barbier, (Sat Jan 19, 11:21 am)
Re: [PATCH] http-push: fix webdav lock leak., Johannes Schindelin, (Sat Jan 19, 7:38 pm)
Re: What's not in 'master' but should be, Mike Hommey, (Sat Jan 19, 2:14 am)
Re: What's not in 'master' but should be, Johannes Schindelin, (Fri Jan 18, 2:36 pm)
Re: What's not in 'master' but should be, Johannes Schindelin, (Mon Feb 18, 3:57 pm)
What's not in 'master', and likely not to be until 1.5.4, Junio C Hamano, (Fri Jan 18, 6:40 am)
Re: What's not in 'master', and likely not to be until 1.5.4, Steffen Prohaska, (Fri Jan 18, 8:53 am)
Re: What's not in 'master', and likely not to be until 1.5.4, Johannes Schindelin, (Fri Jan 18, 9:09 am)
Re: What's not in 'master', and likely not to be until 1.5.4, Steffen Prohaska, (Fri Jan 18, 9:23 am)
Re: What's not in 'master', and likely not to be until 1.5.4, Steffen Prohaska, (Mon Jan 21, 2:42 am)
Re: What's not in 'master', and likely not to be until 1.5.4, Johannes Schindelin, (Fri Jan 18, 4:36 pm)
Re: What's not in 'master', and likely not to be until 1.5.4, Johannes Schindelin, (Fri Jan 18, 4:58 pm)
Re: What's not in 'master', and likely not to be until 1.5.4, Shawn O. Pearce, (Mon Jan 21, 12:46 am)
Re: What's not in 'master', and likely not to be until 1.5.4, Johannes Schindelin, (Mon Jan 21, 6:37 am)
Re: What's not in 'master', and likely not to be until 1.5.4, Shawn O. Pearce, (Wed Jan 23, 12:44 am)
Re: What's not in 'master', and likely not to be until 1.5.4, Johannes Schindelin, (Wed Jan 23, 7:12 am)
Re: What's not in 'master', and likely not to be until 1.5.4, Steffen Prohaska, (Fri Jan 18, 9:04 am)
Re: What's not in 'master', and likely not to be until 1.5.4, Johannes Schindelin, (Fri Jan 18, 9:11 am)
Re: What's not in 'master' but should be, Lars Hjemli, (Fri Jan 18, 6:15 am)
Re: What's not in 'master' but should be, Junio C Hamano, (Fri Jan 18, 6:24 am)
Re: What's not in 'master' but should be, Lars Hjemli, (Fri Jan 18, 6:53 am)
Re: What's not in 'master' but should be, Junio C Hamano, (Fri Jan 18, 7:09 am)
Re: What's not in 'master' but should be, Lars Hjemli, (Fri Jan 18, 7:54 am)
Re: What's not in 'master' but should be, Johannes Schindelin, (Fri Jan 18, 8:34 am)
Re: What's not in 'master' but should be, Lars Hjemli, (Fri Jan 18, 10:19 am)
Re: [PATCH] Teach remote machinery about remotes.default con..., Johannes Schindelin, (Mon Jan 14, 7:18 am)
Re: safecrlf not in 1.5.4, Junio C Hamano, (Mon Jan 14, 3:30 am)
Re: safecrlf not in 1.5.4, Dmitry Potapov, (Mon Jan 14, 5:04 am)
Re: safecrlf not in 1.5.4, Pierre Habouzit, (Mon Jan 14, 1:35 pm)
Re: [msysGit] Re: safecrlf not in 1.5.4, Steffen Prohaska, (Mon Jan 14, 4:29 am)
Re: [msysGit] Re: safecrlf not in 1.5.4, Junio C Hamano, (Mon Jan 14, 3:41 pm)
[PATCH] Teach remote machinery about core.origin config vari..., Mark Levedahl, (Sun Jan 13, 12:27 pm)
[PATCH] git-clone - Set remotes.origin config variable, Mark Levedahl, (Sun Jan 13, 12:27 pm)