From: Finn Arne Gangstad <hidden> Date: 2016-06-15 22:46:33
This series is on top of next.
git remote update <non-existing> would previously silently do nothing.
With this patch series, it will (with 1/3) error out when non-existing groups
are given, and with 2/3 & 3/3 it will use a remote if a group cannot be found.
This enables "git remote update origin" for example. All previous uses
of "git remote update <x>" that did something useful should still work
exactly as before.
There seems to be no current way to check for the existence of a configured
remote, so 2/3 adds a remote_is_configured() function which checks for a
configured remote.
Finn Arne Gangstad (3):
git remote update: Report error for non-existing groups
remote: New function remote_is_configured()
git remote update: Fallback to remote if group does not exist
Documentation/git-remote.txt | 2 +-
builtin-remote.c | 17 ++++++++++++++---
remote.c | 11 +++++++++++
remote.h | 1 +
4 files changed, 27 insertions(+), 4 deletions(-)
From: Finn Arne Gangstad <hidden> Date: 2016-06-15 22:46:33
Previously, git remote update <remote> would fail unless there was
a remote group configured with the same name as the remote.
git remote update will now fall back to using the remote if no matching
group can be found.
This enables "git remote update -p <remote>..." to fetch and prune one
or more remotes, for example.
Signed-off-by: Finn Arne Gangstad <redacted>
---
Documentation/git-remote.txt | 2 +-
builtin-remote.c | 10 ++++++++--
2 files changed, 9 insertions(+), 3 deletions(-)
From: Finn Arne Gangstad <hidden> Date: 2016-06-15 22:46:33
Previously, there was no beautiful way to check for the existence of
a configured remote. remote_get for example would always create the remote
"on demand".
This new function returns 1 if the remote is configured, 0 otherwise.
Signed-off-by: Finn Arne Gangstad <redacted>
---
remote.c | 11 +++++++++++
remote.h | 1 +
2 files changed, 12 insertions(+), 0 deletions(-)
From: Finn Arne Gangstad <hidden> Date: 2016-06-15 22:46:33
Previosly, git remote update <non-existing-group> would just silently fail
and do nothing. Now it will report an error saying that the group does
not exist.
Signed-off-by: Finn Arne Gangstad <redacted>
---
builtin-remote.c | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
@@ -1188,16 +1188,18 @@ struct remote_group {structstring_list*list;}remote_group;-staticintget_remote_group(constchar*key,constchar*value,void*cb)+staticintget_remote_group(constchar*key,constchar*value,void*num_hits){if(!prefixcmp(key,"remotes.")&&!strcmp(key+8,remote_group.name)){/* split list by white space */intspace=strcspn(value," \t\n");while(*value){-if(space>1)+if(space>1){string_list_append(xstrndup(value,space),remote_group.list);+++*((int*)num_hits);+}value+=space+(value[space]!='\0');space=strcspn(value," \t\n");}
@@ -1227,8 +1229,11 @@ static int update(int argc, const char **argv)remote_group.list=&list;for(i=1;i<argc;i++){+intgroups_found=0;remote_group.name=argv[i];-result=git_config(get_remote_group,NULL);+result=git_config(get_remote_group,&groups_found);+if(!groups_found&&(i!=1||strcmp(argv[1],"default")))+die("No such remote group: '%s'",argv[i]);}if(!result&&!list.nr&&argc==2&&!strcmp(argv[1],"default"))
From: Jeff King <hidden> Date: 2016-06-15 22:46:34
On Mon, Apr 06, 2009 at 03:40:59PM +0200, Finn Arne Gangstad wrote:
This series is on top of next.
git remote update <non-existing> would previously silently do nothing.
With this patch series, it will (with 1/3) error out when non-existing groups
are given, and with 2/3 & 3/3 it will use a remote if a group cannot be found.
Great, this was on my todo list so I am happy that procrastination saved
me some work. :)
The patches look fine to me, except that there are no tests. The patch
below adds a "remote groups" test script. There is a slight bit of
overlap with the update tests from t5505, but I don't think it is a
problem.
It is intended to be applied before your series. Your 1/3 would switch
t5506.3 from expect_failure to expect_success, and 3/3 would switch
t5506.6 from failure to success.
-- >8 --
Subject: [PATCH] add tests for remote groups
This tries to systematically cover existing behavior, and
also mark some expect_failure cases for desired behavior.
Signed-off-by: Jeff King <redacted>
---
t/t5506-remote-groups.sh | 81 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 81 insertions(+), 0 deletions(-)
create mode 100755 t/t5506-remote-groups.sh
@@ -0,0 +1,81 @@+#!/bin/sh++test_description='git remote group handling'+../test-lib.sh++mark(){+echo"$1">mark+}++update_repo(){+(cd$1&&+echocontent>>file&&+gitaddfile&&+gitcommit-F../mark)+}++update_repos(){+update_repoone$1&&+update_repotwo$1+}++repo_fetched(){+iftest"`git log -1 --pretty=format:%s $1 --`"="`cat mark`";then+echo>&2"repo was fetched: $1"+return0+fi+echo>&2"repo was not fetched: $1"+return1+}++test_expect_success'setup''+mkdirone&&(cdone&&gitinit)&&+mkdirtwo&&(cdtwo&&gitinit)&&+gitremoteadd-mmasteroneone&&+gitremoteadd-mmastertwotwo+'++test_expect_success'no group updates all''+markupdate-all&&+update_repos&&+gitremoteupdate&&+repo_fetchedone&&+repo_fetchedtwo+'++test_expect_failure'nonexistant group produces error''+marknonexistant&&+update_repos&&+test_must_failgitremoteupdatenonexistant&&+!repo_fetchedone&&+!repo_fetchedtwo+'++test_expect_success'updating group updates all members''+markgroup-all&&+update_repos&&+gitconfig--addremotes.allone&&+gitconfig--addremotes.alltwo&&+gitremoteupdateall&&+repo_fetchedone&&+repo_fetchedtwo+'++test_expect_success'updating group does not update non-members''+markgroup-some&&+update_repos&&+gitconfig--addremotes.someone&&+gitremoteupdatesome&&+repo_fetchedone&&+!repo_fetchedtwo+'++test_expect_failure'updating remote name updates that remote''+markremote-name&&+update_repos&&+gitremoteupdateone&&+repo_fetchedone&&+!repo_fetchedtwo+'++test_done