Skip to content

Commit

Permalink
Be more careful when determining whether a remote was configured
Browse files Browse the repository at this point in the history
One of the really nice features of the ~/.gitconfig file is that users
can override defaults by their own preferred settings for all of their
repositories.

One such default that some users like to override is whether the
"origin" remote gets auto-pruned or not. The user would simply call

	git config --global remote.origin.prune true

and from now on all "origin" remotes would be pruned automatically when
fetching into the local repository.

There is just one catch: now Git thinks that the "origin" remote is
configured, as it does not discern between having a remote whose
fetch (and/or push) URL and refspec is set, and merely having
preemptively-configured, global flags for specific remotes.

Let's fix this by telling Git that a remote is not configured unless any
fetch/push URL or refspect is configured explicitly.

As a special exception, we deem a remote configured also when *only* the
"vcs" setting is configured. The commit a31eeae (remote: use
remote_is_configured() for add and rename, 2016-02-16) specifically
extended our test suite to verify this, so it is safe to assume that there
has been at least one user with a legitimate use case for this.

This fixes git-for-windows#888

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
  • Loading branch information
dscho authored and 0day robot committed Jan 18, 2017
1 parent 9f69f8a commit 562818d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ static void read_remotes_file(struct remote *remote)

if (!f)
return;
remote->configured = 1;
remote->origin = REMOTE_REMOTES;
while (strbuf_getline(&buf, f) != EOF) {
const char *v;
Expand Down Expand Up @@ -289,6 +290,7 @@ static void read_branches_file(struct remote *remote)
return;
}

remote->configured = 1;
remote->origin = REMOTE_BRANCHES;

/*
Expand Down Expand Up @@ -384,21 +386,25 @@ static int handle_config(const char *key, const char *value, void *cb)
if (git_config_string(&v, key, value))
return -1;
add_url(remote, v);
remote->configured = 1;
} else if (!strcmp(subkey, "pushurl")) {
const char *v;
if (git_config_string(&v, key, value))
return -1;
add_pushurl(remote, v);
remote->configured = 1;
} else if (!strcmp(subkey, "push")) {
const char *v;
if (git_config_string(&v, key, value))
return -1;
add_push_refspec(remote, v);
remote->configured = 1;
} else if (!strcmp(subkey, "fetch")) {
const char *v;
if (git_config_string(&v, key, value))
return -1;
add_fetch_refspec(remote, v);
remote->configured = 1;
} else if (!strcmp(subkey, "receivepack")) {
const char *v;
if (git_config_string(&v, key, value))
Expand Down Expand Up @@ -427,6 +433,7 @@ static int handle_config(const char *key, const char *value, void *cb)
return git_config_string((const char **)&remote->http_proxy_authmethod,
key, value);
} else if (!strcmp(subkey, "vcs")) {
remote->configured = 1;
return git_config_string(&remote->foreign_vcs, key, value);
}
return 0;
Expand Down Expand Up @@ -716,7 +723,7 @@ struct remote *pushremote_get(const char *name)

int remote_is_configured(struct remote *remote)
{
return remote && remote->origin;
return remote && remote->configured;
}

int for_each_remote(each_remote_fn fn, void *priv)
Expand Down
2 changes: 1 addition & 1 deletion remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct remote {
struct hashmap_entry ent; /* must be first */

const char *name;
int origin;
int origin, configured;

const char *foreign_vcs;

Expand Down
2 changes: 1 addition & 1 deletion t/t5505-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ test_expect_success 'rename a remote with name prefix of other remote' '
)
'

test_expect_failure 'rename succeeds with existing remote.<target>.prune' '
test_expect_success 'rename succeeds with existing remote.<target>.prune' '
git clone one four.four &&
(
cd four.four &&
Expand Down

0 comments on commit 562818d

Please sign in to comment.