diff options
author | Felipe Contreras <felipe.contreras@gmail.com> | 2014-04-20 14:45:02 -0500 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-04-21 11:46:16 -0700 |
commit | 3e359dccdcbe81164cf05731d0e93fc6a7d5a451 (patch) | |
tree | 9afb90a768f52651515e8bc50f3f6f3208390788 | |
parent | ae0455a56da8bf06f3fd44fbd918ade060c832d8 (diff) | |
download | git-3e359dccdcbe81164cf05731d0e93fc6a7d5a451.tar.gz |
push: add --set-publish option
To setup publish tracking branch, like 'git branch --set-publish'.
Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | Documentation/git-push.txt | 9 | ||||
-rw-r--r-- | builtin/push.c | 2 | ||||
-rwxr-xr-x | t/t5534-push-publish.sh | 70 | ||||
-rw-r--r-- | transport.c | 28 | ||||
-rw-r--r-- | transport.h | 1 |
5 files changed, 100 insertions, 10 deletions
diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index 21cd455508..553a6decf3 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -10,7 +10,8 @@ SYNOPSIS -------- [verse] 'git push' [--all | --mirror | --tags] [--follow-tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>] - [--repo=<repository>] [-f | --force] [--prune] [-v | --verbose] [-u | --set-upstream] + [--repo=<repository>] [-f | --force] [--prune] [-v | --verbose] + [-u | --set-upstream] [-p | --set-publish] [--force-with-lease[=<refname>[:<expect>]]] [--no-verify] [<repository> [<refspec>...]] @@ -231,6 +232,12 @@ useful if you write an alias or script around 'git push'. linkgit:git-pull[1] and other commands. For more information, see 'branch.<name>.merge' in linkgit:git-config[1]. +-p:: +--set-publish:: + For every branch that is up to date or successfully pushed, add + publish branch tracking reference, used by argument-less + linkgit:git-pull[1] and other commands. + --[no-]thin:: These options are passed to linkgit:git-send-pack[1]. A thin transfer significantly reduces the amount of sent data when the sender and diff --git a/builtin/push.c b/builtin/push.c index 31a4aa3396..51d96906b3 100644 --- a/builtin/push.c +++ b/builtin/push.c @@ -508,6 +508,8 @@ int cmd_push(int argc, const char **argv, const char *prefix) OPT_STRING( 0 , "exec", &receivepack, "receive-pack", N_("receive pack program")), OPT_BIT('u', "set-upstream", &flags, N_("set upstream for git pull/status"), TRANSPORT_PUSH_SET_UPSTREAM), + OPT_BIT('p', "set-publish", &flags, N_("set publish for git pull/status"), + TRANSPORT_PUSH_SET_PUBLISH), OPT_BOOL(0, "progress", &progress, N_("force progress reporting")), OPT_BIT(0, "prune", &flags, N_("prune locally removed refs"), TRANSPORT_PUSH_PRUNE), diff --git a/t/t5534-push-publish.sh b/t/t5534-push-publish.sh new file mode 100755 index 0000000000..2037026715 --- /dev/null +++ b/t/t5534-push-publish.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +test_description='push with --set-publish' + +. ./test-lib.sh + +test_expect_success 'setup bare parent' ' + git init --bare parent && + git remote add publish parent +' + +test_expect_success 'setup local commit' ' + echo content >file && + git add file && + git commit -m one +' + +check_config() { + (echo $2; echo $3) >expect.$1 + (git config branch.$1.pushremote + git config branch.$1.push) >actual.$1 + test_cmp expect.$1 actual.$1 +} + +test_expect_success 'push -p master:master' ' + git push -p publish master:master && + check_config master publish refs/heads/master +' + +test_expect_success 'push -u master:other' ' + git push -p publish master:other && + check_config master publish refs/heads/other +' + +test_expect_success 'push -p --dry-run master:otherX' ' + git push -p --dry-run publish master:otherX && + check_config master publish refs/heads/other +' + +test_expect_success 'push -p master2:master2' ' + git branch master2 && + git push -p publish master2:master2 && + check_config master2 publish refs/heads/master2 +' + +test_expect_success 'push -p master2:other2' ' + git push -p publish master2:other2 && + check_config master2 publish refs/heads/other2 +' + +test_expect_success 'push -p :master2' ' + git push -p publish :master2 && + check_config master2 publish refs/heads/other2 +' + +test_expect_success 'push -u --all' ' + git branch all1 && + git branch all2 && + git push -p --all && + check_config all1 publish refs/heads/all1 && + check_config all2 publish refs/heads/all2 +' + +test_expect_success 'push -p HEAD' ' + git checkout -b headbranch && + git push -p publish HEAD && + check_config headbranch publish refs/heads/headbranch +' + +test_done diff --git a/transport.c b/transport.c index 325f03e1ee..bf83ef0515 100644 --- a/transport.c +++ b/transport.c @@ -143,8 +143,8 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list) } } -static void set_upstreams(struct transport *transport, struct ref *refs, - int pretend) +static void set_tracking(struct transport *transport, struct ref *refs, + int pretend, int publish) { struct ref *ref; for (ref = refs; ref; ref = ref->next) { @@ -179,12 +179,18 @@ static void set_upstreams(struct transport *transport, struct ref *refs, if (!remotename || !starts_with(remotename, "refs/heads/")) continue; - if (!pretend) - install_branch_config(BRANCH_CONFIG_VERBOSE, - localname + 11, transport->remote->name, - remotename); - else - printf("Would set upstream of '%s' to '%s' of '%s'\n", + if (!pretend) { + if (publish) + install_branch_publish(localname + 11, + transport->remote->name, + remotename); + else + install_branch_config(BRANCH_CONFIG_VERBOSE, + localname + 11, transport->remote->name, + remotename); + } else + printf("Would set %s of '%s' to '%s' of '%s'\n", + publish ? "publish" : "upstream", localname + 11, remotename + 11, transport->remote->name); } @@ -1129,6 +1135,8 @@ int transport_push(struct transport *transport, /* Maybe FIXME. But no important transport uses this case. */ if (flags & TRANSPORT_PUSH_SET_UPSTREAM) die("This transport does not support using --set-upstream"); + if (flags & TRANSPORT_PUSH_SET_PUBLISH) + die("This transport does not support using --set-publish"); return transport->push(transport, refspec_nr, refspec, flags); } else if (transport->push_refs) { @@ -1207,7 +1215,9 @@ int transport_push(struct transport *transport, reject_reasons); if (flags & TRANSPORT_PUSH_SET_UPSTREAM) - set_upstreams(transport, remote_refs, pretend); + set_tracking(transport, remote_refs, pretend, 0); + if (flags & TRANSPORT_PUSH_SET_PUBLISH) + set_tracking(transport, remote_refs, pretend, 1); if (!(flags & TRANSPORT_PUSH_DRY_RUN)) { struct ref *ref; diff --git a/transport.h b/transport.h index 02ea248db1..324997cc11 100644 --- a/transport.h +++ b/transport.h @@ -123,6 +123,7 @@ struct transport { #define TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND 256 #define TRANSPORT_PUSH_NO_HOOK 512 #define TRANSPORT_PUSH_FOLLOW_TAGS 1024 +#define TRANSPORT_PUSH_SET_PUBLISH 2048 #define TRANSPORT_SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3) #define TRANSPORT_SUMMARY(x) (int)(TRANSPORT_SUMMARY_WIDTH + strlen(x) - gettext_width(x)), (x) |