{"thread":{"id":"22238","subject":"[PATCH v2] Add push --set-upstream","startedAt":"2010-01-15T22:47:10Z","lastAt":"2010-01-16T22:28:17Z","messageCount":15,"participants":["Ilari Liusvaara","Junio C Hamano","Nanako Shiraishi","Tay Ray Chuan","Sverre Rabbelier","Rudolf Polzer"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"131800","messageId":"1263595630-18962-1-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"22238","inReplyTo":null,"subject":"[PATCH v2] Add push --set-upstream","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-01-15T22:47:10Z","receivedAt":"2010-01-15T22:47:10Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"Frequent complaint is lack of easy way to set up upstream (tracking)\nreferences for git pull to work as part of push command. So add switch\n--set-upstream (-u) to do just that.\n\nSigned-off-by: Jeff King <peff@peff.net>\nSigned-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\n---\nChanges from v1:\n- Handle 'git push -u <remote> HEAD' correctly.\n- Add testsuite (thanks Peff), with some additional tests to test delete.\n- Modify documentation for push -u (thanks Matthieu Moy).\n\n Documentation/git-push.txt |    9 +++++-\n builtin-push.c             |    1 +\n t/t5523-push-upstream.sh   |   64 ++++++++++++++++++++++++++++++++++++++++++++\n transport.c                |   49 +++++++++++++++++++++++++++++++++\n transport.h                |    1 +\n 5 files changed, 123 insertions(+), 1 deletions(-)\n create mode 100755 t/t5523-push-upstream.sh\n\ndiff --git a/Documentation/git-push.txt b/Documentation/git-push.txt\nindex e3eb1e8..2a5394b 100644\n--- a/Documentation/git-push.txt\n+++ b/Documentation/git-push.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git push' [--all | --mirror | --tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]\n-\t   [--repo=<repository>] [-f | --force] [-v | --verbose]\n+\t   [--repo=<repository>] [-f | --force] [-v | --verbose] [-u | --set-upstream]\n \t   [<repository> <refspec>...]\n \n DESCRIPTION\n@@ -122,6 +122,13 @@ nor in any Push line of the corresponding remotes file---see below).\n \tthe name \"origin\" is used. For this latter case, this option\n \tcan be used to override the name \"origin\". In other words,\n \tthe difference between these two commands\n+\n+-u::\n+--set-upstream::\n+\tFor every branch that is up to date or successfully pushed, add\n+\tupstream (tracking) reference, used by argument-less\n+\tlinkgit:git-pull[1] and other commands. For more information,\n+\tsee 'branch.<name>.merge' in linkgit:git-config[1].\n +\n --------------------------\n git push public         #1\ndiff --git a/builtin-push.c b/builtin-push.c\nindex 28a26e7..75ddaf4 100644\n--- a/builtin-push.c\n+++ b/builtin-push.c\n@@ -218,6 +218,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)\n \t\tOPT_BOOLEAN( 0 , \"thin\", &thin, \"use thin pack\"),\n \t\tOPT_STRING( 0 , \"receive-pack\", &receivepack, \"receive-pack\", \"receive pack program\"),\n \t\tOPT_STRING( 0 , \"exec\", &receivepack, \"receive-pack\", \"receive pack program\"),\n+\t\tOPT_BIT('u', \"set-upstream\", &flags, \"Set upstream for git pull\", TRANSPORT_PUSH_SET_UPSTREAM),\n \t\tOPT_END()\n \t};\n \ndiff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh\nnew file mode 100755\nindex 0000000..e098d37\n--- /dev/null\n+++ b/t/t5523-push-upstream.sh\n@@ -0,0 +1,64 @@\n+#!/bin/sh\n+\n+test_description='push with --set-upstream'\n+. ./test-lib.sh\n+\n+test_expect_success 'setup bare parent' '\n+\tgit init --bare parent &&\n+\tgit remote add upstream parent\n+'\n+\n+test_expect_success 'setup local commit' '\n+\techo content >file &&\n+\tgit add file &&\n+\tgit commit -m one\n+'\n+\n+check_config() {\n+\t(echo $2; echo $3) >expect.$1\n+\t(git config branch.$1.remote\n+\t git config branch.$1.merge) >actual.$1\n+\ttest_cmp expect.$1 actual.$1\n+}\n+\n+test_expect_success 'push -u master:master' '\n+\tgit push -u upstream master:master &&\n+\tcheck_config master upstream refs/heads/master\n+'\n+\n+test_expect_success 'push -u master:other' '\n+\tgit push -u upstream master:other &&\n+\tcheck_config master upstream refs/heads/other\n+'\n+\n+test_expect_success 'push -u master2:master2' '\n+\tgit branch master2 &&\n+\tgit push -u upstream master2:master2 &&\n+\tcheck_config master2 upstream refs/heads/master2\n+'\n+\n+test_expect_success 'push -u master2:other2' '\n+\tgit push -u upstream master2:other2 &&\n+\tcheck_config master2 upstream refs/heads/other2\n+'\n+\n+test_expect_success 'push -u :master2' '\n+\tgit push -u upstream :master2 &&\n+\tcheck_config master2 upstream refs/heads/other2\n+'\n+\n+test_expect_success 'push -u --all' '\n+\tgit branch all1 &&\n+\tgit branch all2 &&\n+\tgit push -u --all &&\n+\tcheck_config all1 upstream refs/heads/all1 &&\n+\tcheck_config all2 upstream refs/heads/all2\n+'\n+\n+test_expect_success 'push -u HEAD' '\n+\tgit checkout -b headbranch &&\n+\tgit push -u upstream HEAD &&\n+\tcheck_config headbranch upstream refs/heads/headbranch\n+'\n+\n+test_done\ndiff --git a/transport.c b/transport.c\nindex b5332c0..e5b462b 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -8,6 +8,7 @@\n #include \"bundle.h\"\n #include \"dir.h\"\n #include \"refs.h\"\n+#include \"branch.h\"\n \n /* rsync support */\n \n@@ -135,6 +136,47 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)\n \t}\n }\n \n+static void set_upstreams(struct transport *trans, struct ref *refs)\n+{\n+\tstruct ref *i;\n+\tfor (i = refs; i; i = i->next) {\n+\t\tconst char *localname;\n+\t\tconst char *tmp;\n+\t\tconst char *remotename;\n+\t\tunsigned char sha[20];\n+\t\tint flag = 0;\n+\t\t/*\n+\t\t * Check suitability for tracking. Must be successful /\n+\t\t * alreay up-to-date ref create/modify (not delete).\n+\t\t */\n+\t\tif (i->status != REF_STATUS_OK &&\n+\t\t\ti->status != REF_STATUS_UPTODATE)\n+\t\t\tcontinue;\n+\t\tif (!i->peer_ref)\n+\t\t\tcontinue;\n+\t\tif (!i->new_sha1 || is_null_sha1(i->new_sha1))\n+\t\t\tcontinue;\n+\n+\t\t/* Chase symbolic refs (mainly for HEAD). */\n+\t\tlocalname = i->peer_ref->name;\n+\t\tremotename = i->name;\n+\t\ttmp = resolve_ref(localname, sha, 1, &flag);\n+\t\tif (tmp && flag & REF_ISSYMREF &&\n+\t\t\t!prefixcmp(tmp, \"refs/heads/\"))\n+\t\t\tlocalname = tmp;\n+\n+\t\t/* Both source and destination must be local branches. */\n+\t\tif (!localname || prefixcmp(localname, \"refs/heads/\"))\n+\t\t\tcontinue;\n+\t\tif (!remotename || prefixcmp(remotename, \"refs/heads/\"))\n+\t\t\tcontinue;\n+\n+\t\tinstall_branch_config(BRANCH_CONFIG_VERBOSE,\n+\t\t\tlocalname + 11, trans->remote->name,\n+\t\t\tremotename);\n+\t}\n+}\n+\n static const char *rsync_url(const char *url)\n {\n \treturn prefixcmp(url, \"rsync://\") ? skip_prefix(url, \"rsync:\") : url;\n@@ -974,6 +1016,10 @@ int transport_push(struct transport *transport,\n \tverify_remote_names(refspec_nr, refspec);\n \n \tif (transport->push) {\n+\t\t/* Maybe FIXME. But no important transport uses this case. */\n+\t\tif (flags & TRANSPORT_PUSH_SET_UPSTREAM)\n+\t\t\tdie(\"This transport does not support using --set-upstream\");\n+\n \t\treturn transport->push(transport, refspec_nr, refspec, flags);\n \t} else if (transport->push_refs) {\n \t\tstruct ref *remote_refs =\n@@ -1002,6 +1048,9 @@ int transport_push(struct transport *transport,\n \t\t\t\t\tverbose | porcelain, porcelain,\n \t\t\t\t\tnonfastforward);\n \n+\t\tif (flags & TRANSPORT_PUSH_SET_UPSTREAM)\n+\t\t\tset_upstreams(transport, remote_refs);\n+\n \t\tif (!(flags & TRANSPORT_PUSH_DRY_RUN)) {\n \t\t\tstruct ref *ref;\n \t\t\tfor (ref = remote_refs; ref; ref = ref->next)\ndiff --git a/transport.h b/transport.h\nindex 97ba251..c4314dd 100644\n--- a/transport.h\n+++ b/transport.h\n@@ -91,6 +91,7 @@ struct transport {\n #define TRANSPORT_PUSH_VERBOSE 16\n #define TRANSPORT_PUSH_PORCELAIN 32\n #define TRANSPORT_PUSH_QUIET 64\n+#define TRANSPORT_PUSH_SET_UPSTREAM 128\n \n /* Returns a transport suitable for the url */\n struct transport *transport_get(struct remote *, const char *);\n-- \n1.6.6.102.gd6f8f.dirty\n"},{"id":"131813","messageId":"7vzl4frl7i.fsf@alter.siamese.dyndns.org","threadId":"22238","inReplyTo":"1263595630-18962-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-15T23:40:17Z","receivedAt":"2010-01-15T23:40:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ilari Liusvaara <ilari.liusvaara@elisanet.fi> writes:\n\n> @@ -974,6 +1016,10 @@ int transport_push(struct transport *transport,\n>  \tverify_remote_names(refspec_nr, refspec);\n>  \n>  \tif (transport->push) {\n> +\t\t/* Maybe FIXME. But no important transport uses this case. */\n> +\t\tif (flags & TRANSPORT_PUSH_SET_UPSTREAM)\n> +\t\t\tdie(\"This transport does not support using --set-upstream\");\n> +\n\nWould it be better to just warn() and continue instead of dying?  I think\nit can be argued both ways, and I personally think die() is better by\nmaking it more visible that the user does not have the config s/he wanted\nto add, but I am pointing it out just in case somebody thinks of a better\nsolution (of course, doing an extra ls-remote and doing the configuration\nis such a \"better solution\" but that is not what I mean---I am not that\ngreedy).\n\n> @@ -1002,6 +1048,9 @@ int transport_push(struct transport *transport,\n>  \t\t\t\t\tverbose | porcelain, porcelain,\n>  \t\t\t\t\tnonfastforward);\n>  \n> +\t\tif (flags & TRANSPORT_PUSH_SET_UPSTREAM)\n> +\t\t\tset_upstreams(transport, remote_refs);\n> +\n>  \t\tif (!(flags & TRANSPORT_PUSH_DRY_RUN)) {\n>  \t\t\tstruct ref *ref;\n>  \t\t\tfor (ref = remote_refs; ref; ref = ref->next)\n\nShouldn't this honor TRANSPORT_PUSH_DRY_RUN?  IOW, when should it touch\nthe configuration if you do this sequence?\n\n\t# I am paranoid and want to check what happens first\n\tgit push -n --track there this\n        # Ok let's do it for real.\n        git push    --track there this\n"},{"id":"131816","messageId":"7vfx66sz5p.fsf@alter.siamese.dyndns.org","threadId":"22238","inReplyTo":"7vzl4frl7i.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-15T23:53:38Z","receivedAt":"2010-01-15T23:53:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n>         # Ok let's do it for real.\n>         git push    --track there this\n\nUgh; s/--track/--set-upstream/, of course.\n"},{"id":"131818","messageId":"20100116090321.6117@nanako3.lavabit.com","threadId":"22238","inReplyTo":"7vfx66sz5p.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Nanako Shiraishi","fromEmail":"nanako3@lavabit.com","sentAt":"2010-01-16T00:03:21Z","receivedAt":"2010-01-16T00:03:21Z","isPatch":true,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"Quoting Junio C Hamano <gitster@pobox.com>\n\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>>         # Ok let's do it for real.\n>>         git push    --track there this\n>\n> Ugh; s/--track/--set-upstream/, of course.\n\nHow can I use this to say I want to use 'pull --rebase'?\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n"},{"id":"131820","messageId":"7vk4virjzh.fsf@alter.siamese.dyndns.org","threadId":"22238","inReplyTo":"20100116090321.6117@nanako3.lavabit.com","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-16T00:06:42Z","receivedAt":"2010-01-16T00:06:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Nanako Shiraishi <nanako3@lavabit.com> writes:\n\n> Quoting Junio C Hamano <gitster@pobox.com>\n>\n>> Junio C Hamano <gitster@pobox.com> writes:\n>>\n>>>         # Ok let's do it for real.\n>>>         git push    --track there this\n>>\n>> Ugh; s/--track/--set-upstream/, of course.\n>\n> How can I use this to say I want to use 'pull --rebase'?\n\nI dunno; \"git push --set-upstream=rebase\", perhaps?\n"},{"id":"131827","messageId":"be6fef0d1001151653o7ba2cf7et8875eaf4333fc15a@mail.gmail.com","threadId":"22238","inReplyTo":"7vk4virjzh.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-01-16T00:53:14Z","receivedAt":"2010-01-16T00:53:14Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Sat, Jan 16, 2010 at 8:06 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Nanako Shiraishi <nanako3@lavabit.com> writes:\n>\n>> Quoting Junio C Hamano <gitster@pobox.com>\n>>\n>>> Junio C Hamano <gitster@pobox.com> writes:\n>>>\n>>>>         # Ok let's do it for real.\n>>>>         git push    --track there this\n>>>\n>>> Ugh; s/--track/--set-upstream/, of course.\n>>\n>> How can I use this to say I want to use 'pull --rebase'?\n>\n> I dunno; \"git push --set-upstream=rebase\", perhaps?\n\nhow about --setup-merge and --setup-rebase?\n\nAfter all, there's already the config called branch.autosetupmerge and\nbranch.autosetuprebase.\n\n-- \nCheers,\nRay Chuan\n"},{"id":"131828","messageId":"fabb9a1e1001151655r515374f3ybe2a7d4fb20ea532@mail.gmail.com","threadId":"22238","inReplyTo":"be6fef0d1001151653o7ba2cf7et8875eaf4333fc15a@mail.gmail.com","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-01-16T00:55:07Z","receivedAt":"2010-01-16T00:55:07Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Sat, Jan 16, 2010 at 01:53, Tay Ray Chuan <rctay89@gmail.com> wrote:\n> how about --setup-merge and --setup-rebase?\n\nI like it, it also suggests this should be called '--setup-upstream', no?\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"131829","messageId":"be6fef0d1001151658g78af211duc33c9b3ec71bdb57@mail.gmail.com","threadId":"22238","inReplyTo":"fabb9a1e1001151655r515374f3ybe2a7d4fb20ea532@mail.gmail.com","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-01-16T00:58:06Z","receivedAt":"2010-01-16T00:58:06Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Sat, Jan 16, 2010 at 8:55 AM, Sverre Rabbelier <srabbelier@gmail.com> wrote:\n> Heya,\n>\n> On Sat, Jan 16, 2010 at 01:53, Tay Ray Chuan <rctay89@gmail.com> wrote:\n>> how about --setup-merge and --setup-rebase?\n>\n> I like it, it also suggests this should be called '--setup-upstream', no?\n\nif I'm not wrong, --set-upstream (which you want renamed to\n--setup-upstream, right?) means the same thing as what I want to call\n--setup-merge.\n\n-- \nCheers,\nRay Chuan\n"},{"id":"131831","messageId":"be6fef0d1001151700se963950i6932d30bae3ca940@mail.gmail.com","threadId":"22238","inReplyTo":"1263595630-18962-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-01-16T01:00:30Z","receivedAt":"2010-01-16T01:00:30Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nI'm adding people from the \"git push --track\" thread here, since this\nfeature is related to what they want.\n\n(sorry for any line-wrap mangling in the patch.)\n\n-- \nCheers,\nRay Chuan\n\nOn Sat, Jan 16, 2010 at 6:47 AM, Ilari Liusvaara\n<ilari.liusvaara@elisanet.fi> wrote:\n> Frequent complaint is lack of easy way to set up upstream (tracking)\n> references for git pull to work as part of push command. So add switch\n> --set-upstream (-u) to do just that.\n>\n> Signed-off-by: Jeff King <peff@peff.net>\n> Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\n> ---\n> Changes from v1:\n> - Handle 'git push -u <remote> HEAD' correctly.\n> - Add testsuite (thanks Peff), with some additional tests to test delete.\n> - Modify documentation for push -u (thanks Matthieu Moy).\n>\n>  Documentation/git-push.txt |    9 +++++-\n>  builtin-push.c             |    1 +\n>  t/t5523-push-upstream.sh   |   64 ++++++++++++++++++++++++++++++++++++++++++++\n>  transport.c                |   49 +++++++++++++++++++++++++++++++++\n>  transport.h                |    1 +\n>  5 files changed, 123 insertions(+), 1 deletions(-)\n>  create mode 100755 t/t5523-push-upstream.sh\n>\n> diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt\n> index e3eb1e8..2a5394b 100644\n> --- a/Documentation/git-push.txt\n> +++ b/Documentation/git-push.txt\n> @@ -10,7 +10,7 @@ SYNOPSIS\n>  --------\n>  [verse]\n>  'git push' [--all | --mirror | --tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]\n> -          [--repo=<repository>] [-f | --force] [-v | --verbose]\n> +          [--repo=<repository>] [-f | --force] [-v | --verbose] [-u | --set-upstream]\n>           [<repository> <refspec>...]\n>\n>  DESCRIPTION\n> @@ -122,6 +122,13 @@ nor in any Push line of the corresponding remotes file---see below).\n>        the name \"origin\" is used. For this latter case, this option\n>        can be used to override the name \"origin\". In other words,\n>        the difference between these two commands\n> +\n> +-u::\n> +--set-upstream::\n> +       For every branch that is up to date or successfully pushed, add\n> +       upstream (tracking) reference, used by argument-less\n> +       linkgit:git-pull[1] and other commands. For more information,\n> +       see 'branch.<name>.merge' in linkgit:git-config[1].\n>  +\n>  --------------------------\n>  git push public         #1\n> diff --git a/builtin-push.c b/builtin-push.c\n> index 28a26e7..75ddaf4 100644\n> --- a/builtin-push.c\n> +++ b/builtin-push.c\n> @@ -218,6 +218,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)\n>                OPT_BOOLEAN( 0 , \"thin\", &thin, \"use thin pack\"),\n>                OPT_STRING( 0 , \"receive-pack\", &receivepack, \"receive-pack\", \"receive pack program\"),\n>                OPT_STRING( 0 , \"exec\", &receivepack, \"receive-pack\", \"receive pack program\"),\n> +               OPT_BIT('u', \"set-upstream\", &flags, \"Set upstream for git pull\", TRANSPORT_PUSH_SET_UPSTREAM),\n>                OPT_END()\n>        };\n>\n> diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh\n> new file mode 100755\n> index 0000000..e098d37\n> --- /dev/null\n> +++ b/t/t5523-push-upstream.sh\n> @@ -0,0 +1,64 @@\n> +#!/bin/sh\n> +\n> +test_description='push with --set-upstream'\n> +. ./test-lib.sh\n> +\n> +test_expect_success 'setup bare parent' '\n> +       git init --bare parent &&\n> +       git remote add upstream parent\n> +'\n> +\n> +test_expect_success 'setup local commit' '\n> +       echo content >file &&\n> +       git add file &&\n> +       git commit -m one\n> +'\n> +\n> +check_config() {\n> +       (echo $2; echo $3) >expect.$1\n> +       (git config branch.$1.remote\n> +        git config branch.$1.merge) >actual.$1\n> +       test_cmp expect.$1 actual.$1\n> +}\n> +\n> +test_expect_success 'push -u master:master' '\n> +       git push -u upstream master:master &&\n> +       check_config master upstream refs/heads/master\n> +'\n> +\n> +test_expect_success 'push -u master:other' '\n> +       git push -u upstream master:other &&\n> +       check_config master upstream refs/heads/other\n> +'\n> +\n> +test_expect_success 'push -u master2:master2' '\n> +       git branch master2 &&\n> +       git push -u upstream master2:master2 &&\n> +       check_config master2 upstream refs/heads/master2\n> +'\n> +\n> +test_expect_success 'push -u master2:other2' '\n> +       git push -u upstream master2:other2 &&\n> +       check_config master2 upstream refs/heads/other2\n> +'\n> +\n> +test_expect_success 'push -u :master2' '\n> +       git push -u upstream :master2 &&\n> +       check_config master2 upstream refs/heads/other2\n> +'\n> +\n> +test_expect_success 'push -u --all' '\n> +       git branch all1 &&\n> +       git branch all2 &&\n> +       git push -u --all &&\n> +       check_config all1 upstream refs/heads/all1 &&\n> +       check_config all2 upstream refs/heads/all2\n> +'\n> +\n> +test_expect_success 'push -u HEAD' '\n> +       git checkout -b headbranch &&\n> +       git push -u upstream HEAD &&\n> +       check_config headbranch upstream refs/heads/headbranch\n> +'\n> +\n> +test_done\n> diff --git a/transport.c b/transport.c\n> index b5332c0..e5b462b 100644\n> --- a/transport.c\n> +++ b/transport.c\n> @@ -8,6 +8,7 @@\n>  #include \"bundle.h\"\n>  #include \"dir.h\"\n>  #include \"refs.h\"\n> +#include \"branch.h\"\n>\n>  /* rsync support */\n>\n> @@ -135,6 +136,47 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)\n>        }\n>  }\n>\n> +static void set_upstreams(struct transport *trans, struct ref *refs)\n> +{\n> +       struct ref *i;\n> +       for (i = refs; i; i = i->next) {\n> +               const char *localname;\n> +               const char *tmp;\n> +               const char *remotename;\n> +               unsigned char sha[20];\n> +               int flag = 0;\n> +               /*\n> +                * Check suitability for tracking. Must be successful /\n> +                * alreay up-to-date ref create/modify (not delete).\n> +                */\n> +               if (i->status != REF_STATUS_OK &&\n> +                       i->status != REF_STATUS_UPTODATE)\n> +                       continue;\n> +               if (!i->peer_ref)\n> +                       continue;\n> +               if (!i->new_sha1 || is_null_sha1(i->new_sha1))\n> +                       continue;\n> +\n> +               /* Chase symbolic refs (mainly for HEAD). */\n> +               localname = i->peer_ref->name;\n> +               remotename = i->name;\n> +               tmp = resolve_ref(localname, sha, 1, &flag);\n> +               if (tmp && flag & REF_ISSYMREF &&\n> +                       !prefixcmp(tmp, \"refs/heads/\"))\n> +                       localname = tmp;\n> +\n> +               /* Both source and destination must be local branches. */\n> +               if (!localname || prefixcmp(localname, \"refs/heads/\"))\n> +                       continue;\n> +               if (!remotename || prefixcmp(remotename, \"refs/heads/\"))\n> +                       continue;\n> +\n> +               install_branch_config(BRANCH_CONFIG_VERBOSE,\n> +                       localname + 11, trans->remote->name,\n> +                       remotename);\n> +       }\n> +}\n> +\n>  static const char *rsync_url(const char *url)\n>  {\n>        return prefixcmp(url, \"rsync://\") ? skip_prefix(url, \"rsync:\") : url;\n> @@ -974,6 +1016,10 @@ int transport_push(struct transport *transport,\n>        verify_remote_names(refspec_nr, refspec);\n>\n>        if (transport->push) {\n> +               /* Maybe FIXME. But no important transport uses this case. */\n> +               if (flags & TRANSPORT_PUSH_SET_UPSTREAM)\n> +                       die(\"This transport does not support using --set-upstream\");\n> +\n>                return transport->push(transport, refspec_nr, refspec, flags);\n>        } else if (transport->push_refs) {\n>                struct ref *remote_refs =\n> @@ -1002,6 +1048,9 @@ int transport_push(struct transport *transport,\n>                                        verbose | porcelain, porcelain,\n>                                        nonfastforward);\n>\n> +               if (flags & TRANSPORT_PUSH_SET_UPSTREAM)\n> +                       set_upstreams(transport, remote_refs);\n> +\n>                if (!(flags & TRANSPORT_PUSH_DRY_RUN)) {\n>                        struct ref *ref;\n>                        for (ref = remote_refs; ref; ref = ref->next)\n> diff --git a/transport.h b/transport.h\n> index 97ba251..c4314dd 100644\n> --- a/transport.h\n> +++ b/transport.h\n> @@ -91,6 +91,7 @@ struct transport {\n>  #define TRANSPORT_PUSH_VERBOSE 16\n>  #define TRANSPORT_PUSH_PORCELAIN 32\n>  #define TRANSPORT_PUSH_QUIET 64\n> +#define TRANSPORT_PUSH_SET_UPSTREAM 128\n>\n>  /* Returns a transport suitable for the url */\n>  struct transport *transport_get(struct remote *, const char *);\n> --\n> 1.6.6.102.gd6f8f.dirty\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n>\n"},{"id":"131832","messageId":"fabb9a1e1001151702i9c38190yb260debfee7e836d@mail.gmail.com","threadId":"22238","inReplyTo":"be6fef0d1001151658g78af211duc33c9b3ec71bdb57@mail.gmail.com","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Sverre Rabbelier","fromEmail":"srabbelier@gmail.com","sentAt":"2010-01-16T01:02:12Z","receivedAt":"2010-01-16T01:02:12Z","isPatch":true,"sender":{"key":"srabbelier@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3098?v=4"},"body":"Heya,\n\nOn Sat, Jan 16, 2010 at 01:58, Tay Ray Chuan <rctay89@gmail.com> wrote:\n> if I'm not wrong, --set-upstream (which you want renamed to\n> --setup-upstream, right?) means the same thing as what I want to call\n> --setup-merge.\n\nAh, correct; that should teach me not to send emails when it's almost 2am :).\n\n-- \nCheers,\n\nSverre Rabbelier\n"},{"id":"131837","messageId":"7vhbqmn9c4.fsf@alter.siamese.dyndns.org","threadId":"22238","inReplyTo":"be6fef0d1001151653o7ba2cf7et8875eaf4333fc15a@mail.gmail.com","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-16T01:10:19Z","receivedAt":"2010-01-16T01:10:19Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tay Ray Chuan <rctay89@gmail.com> writes:\n\n> Hi,\n>\n> On Sat, Jan 16, 2010 at 8:06 AM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Nanako Shiraishi <nanako3@lavabit.com> writes:\n>>\n>>> Quoting Junio C Hamano <gitster@pobox.com>\n>>>\n>>>> Junio C Hamano <gitster@pobox.com> writes:\n>>>>\n>>>>>         # Ok let's do it for real.\n>>>>>         git push    --track there this\n>>>>\n>>>> Ugh; s/--track/--set-upstream/, of course.\n>>>\n>>> How can I use this to say I want to use 'pull --rebase'?\n>>\n>> I dunno; \"git push --set-upstream=rebase\", perhaps?\n>\n> how about --setup-merge and --setup-rebase?\n>\n> After all, there's already the config called branch.autosetupmerge and\n> branch.autosetuprebase.\n\nDo you mean Ilari's patch already sets up branch.name.rebase for people\nwith branch.autosetuprebase true?\n\nIf so, it might be better to keep \"--set-upstream\" as is, and have a way\nto countermand that \"autosetuprebase\" default.\n"},{"id":"131849","messageId":"7vljfyiswv.fsf@alter.siamese.dyndns.org","threadId":"22238","inReplyTo":"7vhbqmn9c4.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-16T04:18:40Z","receivedAt":"2010-01-16T04:18:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Tay Ray Chuan <rctay89@gmail.com> writes:\n>\n>> After all, there's already the config called branch.autosetupmerge and\n>> branch.autosetuprebase.\n>\n> Do you mean Ilari's patch already sets up branch.name.rebase for people\n> with branch.autosetuprebase true?\n\nI checked; the patch uses install_branch_config() so it should get this\nright automatically.\n\nI'll queue the v2 patch on 'pu'; we might want an update to move the code\ninside \"unless --dry-run\" condition, but other than that I think what we\nreviewed in this thread was pretty good.\n"},{"id":"131852","messageId":"be6fef0d1001152055j2f178ecifc8e0265446ab75f@mail.gmail.com","threadId":"22238","inReplyTo":"7vljfyiswv.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-01-16T04:55:12Z","receivedAt":"2010-01-16T04:55:12Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Sat, Jan 16, 2010 at 12:18 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Junio C Hamano <gitster@pobox.com> writes:\n>\n>> Tay Ray Chuan <rctay89@gmail.com> writes:\n>>\n>>> After all, there's already the config called branch.autosetupmerge and\n>>> branch.autosetuprebase.\n>>\n>> Do you mean Ilari's patch already sets up branch.name.rebase for people\n>> with branch.autosetuprebase true?\n>\n> I checked; the patch uses install_branch_config() so it should get this\n> right automatically.\n\nok, then ignore my suggestion about --setup-merge and --setup-rebase.\n\nI guess Nanako's query about 'pull --rebase' is settled as well.\n\n-- \nCheers,\nRay Chuan\n"},{"id":"131894","messageId":"20100116181350.GA28938@rm.endoftheinternet.org","threadId":"22238","inReplyTo":"be6fef0d1001151700se963950i6932d30bae3ca940@mail.gmail.com","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Rudolf Polzer","fromEmail":"divverent@alientrap.org","sentAt":"2010-01-16T18:13:51Z","receivedAt":"2010-01-16T18:13:51Z","isPatch":true,"sender":{"key":"divverent@alientrap.org","avatar":null},"body":"On Sat, Jan 16, 2010 at 09:00:30AM +0800, Tay Ray Chuan wrote:\n> Hi,\n> \n> I'm adding people from the \"git push --track\" thread here, since this\n> feature is related to what they want.\n> \n> (sorry for any line-wrap mangling in the patch.)\n\nLooks perfect to me, and if people want it, one could add the same option as an\nalias to the current --track option to the checkout and branch commands.\n\n> > +               /* Chase symbolic refs (mainly for HEAD). */\n> > +               localname = i->peer_ref->name;\n> > +               remotename = i->name;\n> > +               tmp = resolve_ref(localname, sha, 1, &flag);\n> > +               if (tmp && flag & REF_ISSYMREF &&\n> > +                       !prefixcmp(tmp, \"refs/heads/\"))\n> > +                       localname = tmp;\n\nI would never have thought of that case - good catch.\n\n> > @@ -974,6 +1016,10 @@ int transport_push(struct transport *transport,\n> >        verify_remote_names(refspec_nr, refspec);\n> >\n> >        if (transport->push) {\n> > +               /* Maybe FIXME. But no important transport uses this case. */\n> > +               if (flags & TRANSPORT_PUSH_SET_UPSTREAM)\n> > +                       die(\"This transport does not support using --set-upstream\");\n> > +\n\nThat's ONE way to do it - and seriously, I don't know if anyone uses that\ntransport :P\n\nHowever, one possible improvement for this case would be setting ALL pushed\nrefs as tracking if the push succeeded, and none otherwise.\n\nAre new transports going to be added that use transport->push, or is that\ninterface deprecated anyway?\n\nBest regards,\n\nRudolf Polzer\n"},{"id":"131915","messageId":"20100117072817.6117@nanako3.lavabit.com","threadId":"22238","inReplyTo":"be6fef0d1001152055j2f178ecifc8e0265446ab75f@mail.gmail.com","subject":"Re: [PATCH v2] Add push --set-upstream","fromName":"Nanako Shiraishi","fromEmail":"nanako3@lavabit.com","sentAt":"2010-01-16T22:28:17Z","receivedAt":"2010-01-16T22:28:17Z","isPatch":true,"sender":{"key":"nanako3@lavabit.com","avatar":"https://gravatar.com/avatar/3777b9e201c5883a62b1a6fdf7c53f2d712d1d80989146063ea861e33aad72a8?d=mp&s=160"},"body":"Quoting Tay Ray Chuan <rctay89@gmail.com>\n\n> Hi,\n>\n> On Sat, Jan 16, 2010 at 12:18 PM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Junio C Hamano <gitster@pobox.com> writes:\n>>\n>>> Tay Ray Chuan <rctay89@gmail.com> writes:\n>>>\n>>>> After all, there's already the config called branch.autosetupmerge and\n>>>> branch.autosetuprebase.\n>>>\n>>> Do you mean Ilari's patch already sets up branch.name.rebase for people\n>>> with branch.autosetuprebase true?\n>>\n>> I checked; the patch uses install_branch_config() so it should get this\n>> right automatically.\n>\n> ok, then ignore my suggestion about --setup-merge and --setup-rebase.\n>\n> I guess Nanako's query about 'pull --rebase' is settled as well.\n\nI have branch.autosetuprebase so 'git push -u' is good enough for me.\nThanks.\n\n-- \nNanako Shiraishi\nhttp://ivory.ap.teacup.com/nanako3/\n"}]}