This introduces a new configuration variable, remotes.default, 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., remotes.default is used when on a detached head or any other non-tracking branch). Signed-off-by: Mark Levedahl <mlevedahl@xxxxxxxxx> --- 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 1b6d6d6..01ce295 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -800,6 +800,12 @@ remote.<name>.tagopt:: Setting this value to --no-tags disables automatic tag following when fetching from remote <name> +remotes.default:: + 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. + remotes.<group>:: The list of remotes which are fetched by "git remote update <group>". See linkgit:git-remote[1]. diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 695a409..1b235e0 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 "remotes.default" || + echo origin } get_remote_default_refs_for_push () { diff --git a/remote.c b/remote.c index 0e00680..4937237 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 *remotes_default_name; #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, "remotes.default")) { + if (value) + remotes_default_name = 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 = remotes_default_name ? + remotes_default_name : xstrdup("origin"); + } } struct refspec *parse_ref_spec(int nr_refspec, const char **refspec) -- 1.5.4.rc2.99.g3ef7-dirty - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html