threads / patch / 22238

v2Add push --set-upstream

Subject: [PATCH v2] Add push --set-upstream

## tl;dr

15 messages between Jan 15, 2010 and Jan 16, 2010. Diffs are folded; open one to read it.

replies: 14people: 6as markdown or json

Ilari Liusvaara· Jan 15, 2010, 22:47 UTC · lore

Frequent complaint is lack of easy way to set up upstream (tracking) references for git pull to work as part of push command. So add switch --set-upstream (-u) to do just that.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
---
Changes from v1:
- Handle 'git push -u <remote> HEAD' correctly.
- Add testsuite (thanks Peff), with some additional tests to test delete.
- Modify documentation for push -u (thanks Matthieu Moy).
 Documentation/git-push.txt |    9 +++++-
 builtin-push.c             |    1 +
 t/t5523-push-upstream.sh   |   64 ++++++++++++++++++++++++++++++++++++++++++++
 transport.c                |   49 +++++++++++++++++++++++++++++++++
 transport.h                |    1 +
 5 files changed, 123 insertions(+), 1 deletions(-)
 create mode 100755 t/t5523-push-upstream.sh
Show changes to 5 files +123 −1

Documentation/git-push.txt, builtin-push.c, t/t5523-push-upstream.sh, transport.c, transport.h

diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index e3eb1e8..2a5394b 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git push' [--all | --mirror | --tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
-	   [--repo=<repository>] [-f | --force] [-v | --verbose]
+	   [--repo=<repository>] [-f | --force] [-v | --verbose] [-u | --set-upstream]
 	   [<repository> <refspec>...]
 
 DESCRIPTION
@@ -122,6 +122,13 @@ nor in any Push line of the corresponding remotes file---see below).
 	the name "origin" is used. For this latter case, this option
 	can be used to override the name "origin". In other words,
 	the difference between these two commands
+
+-u::
+--set-upstream::
+	For every branch that is up to date or successfully pushed, add
+	upstream (tracking) reference, used by argument-less
+	linkgit:git-pull[1] and other commands. For more information,
+	see 'branch.<name>.merge' in linkgit:git-config[1].
 +
 --------------------------
 git push public         #1
diff --git a/builtin-push.c b/builtin-push.c
index 28a26e7..75ddaf4 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -218,6 +218,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
 		OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", "receive pack program"),
 		OPT_STRING( 0 , "exec", &receivepack, "receive-pack", "receive pack program"),
+		OPT_BIT('u', "set-upstream", &flags, "Set upstream for git pull", TRANSPORT_PUSH_SET_UPSTREAM),
 		OPT_END()
 	};
 
diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh
new file mode 100755
index 0000000..e098d37
--- /dev/null
+++ b/t/t5523-push-upstream.sh
@@ -0,0 +1,64 @@
+#!/bin/sh
+
+test_description='push with --set-upstream'
+. ./test-lib.sh
+
+test_expect_success 'setup bare parent' '
+	git init --bare parent &&
+	git remote add upstream 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.remote
+	 git config branch.$1.merge) >actual.$1
+	test_cmp expect.$1 actual.$1
+}
+
+test_expect_success 'push -u master:master' '
+	git push -u upstream master:master &&
+	check_config master upstream refs/heads/master
+'
+
+test_expect_success 'push -u master:other' '
+	git push -u upstream master:other &&
+	check_config master upstream refs/heads/other
+'
+
+test_expect_success 'push -u master2:master2' '
+	git branch master2 &&
+	git push -u upstream master2:master2 &&
+	check_config master2 upstream refs/heads/master2
+'
+
+test_expect_success 'push -u master2:other2' '
+	git push -u upstream master2:other2 &&
+	check_config master2 upstream refs/heads/other2
+'
+
+test_expect_success 'push -u :master2' '
+	git push -u upstream :master2 &&
+	check_config master2 upstream refs/heads/other2
+'
+
+test_expect_success 'push -u --all' '
+	git branch all1 &&
+	git branch all2 &&
+	git push -u --all &&
+	check_config all1 upstream refs/heads/all1 &&
+	check_config all2 upstream refs/heads/all2
+'
+
+test_expect_success 'push -u HEAD' '
+	git checkout -b headbranch &&
+	git push -u upstream HEAD &&
+	check_config headbranch upstream refs/heads/headbranch
+'
+
+test_done
diff --git a/transport.c b/transport.c
index b5332c0..e5b462b 100644
--- a/transport.c
+++ b/transport.c
@@ -8,6 +8,7 @@
 #include "bundle.h"
 #include "dir.h"
 #include "refs.h"
+#include "branch.h"
 
 /* rsync support */
 
@@ -135,6 +136,47 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
 	}
 }
 
+static void set_upstreams(struct transport *trans, struct ref *refs)
+{
+	struct ref *i;
+	for (i = refs; i; i = i->next) {
+		const char *localname;
+		const char *tmp;
+		const char *remotename;
+		unsigned char sha[20];
+		int flag = 0;
+		/*
+		 * Check suitability for tracking. Must be successful /
+		 * alreay up-to-date ref create/modify (not delete).
+		 */
+		if (i->status != REF_STATUS_OK &&
+			i->status != REF_STATUS_UPTODATE)
+			continue;
+		if (!i->peer_ref)
+			continue;
+		if (!i->new_sha1 || is_null_sha1(i->new_sha1))
+			continue;
+
+		/* Chase symbolic refs (mainly for HEAD). */
+		localname = i->peer_ref->name;
+		remotename = i->name;
+		tmp = resolve_ref(localname, sha, 1, &flag);
+		if (tmp && flag & REF_ISSYMREF &&
+			!prefixcmp(tmp, "refs/heads/"))
+			localname = tmp;
+
+		/* Both source and destination must be local branches. */
+		if (!localname || prefixcmp(localname, "refs/heads/"))
+			continue;
+		if (!remotename || prefixcmp(remotename, "refs/heads/"))
+			continue;
+
+		install_branch_config(BRANCH_CONFIG_VERBOSE,
+			localname + 11, trans->remote->name,
+			remotename);
+	}
+}
+
 static const char *rsync_url(const char *url)
 {
 	return prefixcmp(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
@@ -974,6 +1016,10 @@ int transport_push(struct transport *transport,
 	verify_remote_names(refspec_nr, refspec);
 
 	if (transport->push) {
+		/* Maybe FIXME. But no important transport uses this case. */
+		if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
+			die("This transport does not support using --set-upstream");
+
 		return transport->push(transport, refspec_nr, refspec, flags);
 	} else if (transport->push_refs) {
 		struct ref *remote_refs =
@@ -1002,6 +1048,9 @@ int transport_push(struct transport *transport,
 					verbose | porcelain, porcelain,
 					nonfastforward);
 
+		if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
+			set_upstreams(transport, remote_refs);
+
 		if (!(flags & TRANSPORT_PUSH_DRY_RUN)) {
 			struct ref *ref;
 			for (ref = remote_refs; ref; ref = ref->next)
diff --git a/transport.h b/transport.h
index 97ba251..c4314dd 100644
--- a/transport.h
+++ b/transport.h
@@ -91,6 +91,7 @@ struct transport {
 #define TRANSPORT_PUSH_VERBOSE 16
 #define TRANSPORT_PUSH_PORCELAIN 32
 #define TRANSPORT_PUSH_QUIET 64
+#define TRANSPORT_PUSH_SET_UPSTREAM 128
 
 /* Returns a transport suitable for the url */
 struct transport *transport_get(struct remote *, const char *);
-- 
1.6.6.102.gd6f8f.dirty
Junio C Hamano· Jan 15, 2010, 23:40 UTC · re: Ilari Liusvaara · lore

Re: [PATCH v2] Add push --set-upstream

Ilari Liusvaara <ilari.liusvaara@elisanet.fi> writes:
Show 8 quoted lines
> @@ -974,6 +1016,10 @@ int transport_push(struct transport *transport,
>  	verify_remote_names(refspec_nr, refspec);
>  
>  	if (transport->push) {
> +		/* Maybe FIXME. But no important transport uses this case. */
> +		if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
> +			die("This transport does not support using --set-upstream");
> +

Would it be better to just warn() and continue instead of dying? I think it can be argued both ways, and I personally think die() is better by making it more visible that the user does not have the config s/he wanted to add, but I am pointing it out just in case somebody thinks of a better solution (of course, doing an extra ls-remote and doing the configuration is such a "better solution" but that is not what I mean---I am not that greedy).

Show 10 quoted lines
> @@ -1002,6 +1048,9 @@ int transport_push(struct transport *transport,
>  					verbose | porcelain, porcelain,
>  					nonfastforward);
>  
> +		if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
> +			set_upstreams(transport, remote_refs);
> +
>  		if (!(flags & TRANSPORT_PUSH_DRY_RUN)) {
>  			struct ref *ref;
>  			for (ref = remote_refs; ref; ref = ref->next)

Shouldn't this honor TRANSPORT_PUSH_DRY_RUN? IOW, when should it touch the configuration if you do this sequence?

	# I am paranoid and want to check what happens first
	git push -n --track there this
        # Ok let's do it for real.
        git push    --track there this
Nanako Shiraishi· Jan 16, 2010, 00:03 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] Add push --set-upstream

Quoting Junio C Hamano <gitster@pobox.com>
Show 6 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>>         # Ok let's do it for real.
>>         git push    --track there this
>
> Ugh; s/--track/--set-upstream/, of course.
How can I use this to say I want to use 'pull --rebase'?
-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
Junio C Hamano· Jan 16, 2010, 00:06 UTC · re: Nanako Shiraishi · lore

Re: [PATCH v2] Add push --set-upstream

Nanako Shiraishi <nanako3@lavabit.com> writes:
Show 10 quoted lines
> Quoting Junio C Hamano <gitster@pobox.com>
>
>> Junio C Hamano <gitster@pobox.com> writes:
>>
>>>         # Ok let's do it for real.
>>>         git push    --track there this
>>
>> Ugh; s/--track/--set-upstream/, of course.
>
> How can I use this to say I want to use 'pull --rebase'?
I dunno; "git push --set-upstream=rebase", perhaps?
Tay Ray Chuan· Jan 16, 2010, 00:53 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] Add push --set-upstream

Hi,
On Sat, Jan 16, 2010 at 8:06 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 14 quoted lines
> Nanako Shiraishi <nanako3@lavabit.com> writes:
>
>> Quoting Junio C Hamano <gitster@pobox.com>
>>
>>> Junio C Hamano <gitster@pobox.com> writes:
>>>
>>>>         # Ok let's do it for real.
>>>>         git push    --track there this
>>>
>>> Ugh; s/--track/--set-upstream/, of course.
>>
>> How can I use this to say I want to use 'pull --rebase'?
>
> I dunno; "git push --set-upstream=rebase", perhaps?
how about --setup-merge and --setup-rebase?

After all, there's already the config called branch.autosetupmerge and branch.autosetuprebase.

-- 
Cheers,
Ray Chuan
Sverre Rabbelier· Jan 16, 2010, 00:55 UTC · re: Tay Ray Chuan · lore

Re: [PATCH v2] Add push --set-upstream

Heya,
On Sat, Jan 16, 2010 at 01:53, Tay Ray Chuan <rctay89@gmail.com> wrote:
> how about --setup-merge and --setup-rebase?
I like it, it also suggests this should be called '--setup-upstream', no?
-- 
Cheers,

Sverre Rabbelier
Tay Ray Chuan· Jan 16, 2010, 00:58 UTC · re: Sverre Rabbelier · lore

Re: [PATCH v2] Add push --set-upstream

Hi,
On Sat, Jan 16, 2010 at 8:55 AM, Sverre Rabbelier <srabbelier@gmail.com> wrote:
Show 6 quoted lines
> Heya,
>
> On Sat, Jan 16, 2010 at 01:53, Tay Ray Chuan <rctay89@gmail.com> wrote:
>> how about --setup-merge and --setup-rebase?
>
> I like it, it also suggests this should be called '--setup-upstream', no?

if I'm not wrong, --set-upstream (which you want renamed to --setup-upstream, right?) means the same thing as what I want to call --setup-merge.

-- 
Cheers,
Ray Chuan
Sverre Rabbelier· Jan 16, 2010, 01:02 UTC · re: Tay Ray Chuan · lore

Re: [PATCH v2] Add push --set-upstream

Heya,
On Sat, Jan 16, 2010 at 01:58, Tay Ray Chuan <rctay89@gmail.com> wrote:
> if I'm not wrong, --set-upstream (which you want renamed to
> --setup-upstream, right?) means the same thing as what I want to call
> --setup-merge.
Ah, correct; that should teach me not to send emails when it's almost 2am :).
-- 
Cheers,

Sverre Rabbelier
Junio C Hamano· Jan 16, 2010, 01:10 UTC · re: Tay Ray Chuan · lore

Re: [PATCH v2] Add push --set-upstream

Tay Ray Chuan <rctay89@gmail.com> writes:
Show 22 quoted lines
> Hi,
>
> On Sat, Jan 16, 2010 at 8:06 AM, Junio C Hamano <gitster@pobox.com> wrote:
>> Nanako Shiraishi <nanako3@lavabit.com> writes:
>>
>>> Quoting Junio C Hamano <gitster@pobox.com>
>>>
>>>> Junio C Hamano <gitster@pobox.com> writes:
>>>>
>>>>>         # Ok let's do it for real.
>>>>>         git push    --track there this
>>>>
>>>> Ugh; s/--track/--set-upstream/, of course.
>>>
>>> How can I use this to say I want to use 'pull --rebase'?
>>
>> I dunno; "git push --set-upstream=rebase", perhaps?
>
> how about --setup-merge and --setup-rebase?
>
> After all, there's already the config called branch.autosetupmerge and
> branch.autosetuprebase.

Do you mean Ilari's patch already sets up branch.name.rebase for people with branch.autosetuprebase true?

If so, it might be better to keep "--set-upstream" as is, and have a way to countermand that "autosetuprebase" default.

Junio C Hamano· Jan 16, 2010, 04:18 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] Add push --set-upstream

Junio C Hamano <gitster@pobox.com> writes:
Show 7 quoted lines
> Tay Ray Chuan <rctay89@gmail.com> writes:
>
>> After all, there's already the config called branch.autosetupmerge and
>> branch.autosetuprebase.
>
> Do you mean Ilari's patch already sets up branch.name.rebase for people
> with branch.autosetuprebase true?

I checked; the patch uses install_branch_config() so it should get this right automatically.

I'll queue the v2 patch on 'pu'; we might want an update to move the code inside "unless --dry-run" condition, but other than that I think what we reviewed in this thread was pretty good.

Tay Ray Chuan· Jan 16, 2010, 04:55 UTC · re: Junio C Hamano · lore

Re: [PATCH v2] Add push --set-upstream

Hi,
On Sat, Jan 16, 2010 at 12:18 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
> Junio C Hamano <gitster@pobox.com> writes:
>
>> Tay Ray Chuan <rctay89@gmail.com> writes:
>>
>>> After all, there's already the config called branch.autosetupmerge and
>>> branch.autosetuprebase.
>>
>> Do you mean Ilari's patch already sets up branch.name.rebase for people
>> with branch.autosetuprebase true?
>
> I checked; the patch uses install_branch_config() so it should get this
> right automatically.
ok, then ignore my suggestion about --setup-merge and --setup-rebase.
I guess Nanako's query about 'pull --rebase' is settled as well.
-- 
Cheers,
Ray Chuan
Nanako Shiraishi· Jan 16, 2010, 22:28 UTC · re: Tay Ray Chuan · lore

Re: [PATCH v2] Add push --set-upstream

Quoting Tay Ray Chuan <rctay89@gmail.com>
Show 19 quoted lines
> Hi,
>
> On Sat, Jan 16, 2010 at 12:18 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> Junio C Hamano <gitster@pobox.com> writes:
>>
>>> Tay Ray Chuan <rctay89@gmail.com> writes:
>>>
>>>> After all, there's already the config called branch.autosetupmerge and
>>>> branch.autosetuprebase.
>>>
>>> Do you mean Ilari's patch already sets up branch.name.rebase for people
>>> with branch.autosetuprebase true?
>>
>> I checked; the patch uses install_branch_config() so it should get this
>> right automatically.
>
> ok, then ignore my suggestion about --setup-merge and --setup-rebase.
>
> I guess Nanako's query about 'pull --rebase' is settled as well.

I have branch.autosetuprebase so 'git push -u' is good enough for me. Thanks.

-- 
Nanako Shiraishi
http://ivory.ap.teacup.com/nanako3/
Tay Ray Chuan· Jan 16, 2010, 01:00 UTC · re: Ilari Liusvaara · lore

Re: [PATCH v2] Add push --set-upstream

Hi,

I'm adding people from the "git push --track" thread here, since this feature is related to what they want.

(sorry for any line-wrap mangling in the patch.)
-- 
Cheers,
Ray Chuan

On Sat, Jan 16, 2010 at 6:47 AM, Ilari Liusvaara
<ilari.liusvaara@elisanet.fi> wrote:
> Frequent complaint is lack of easy way to set up upstream (tracking)
> references for git pull to work as part of push command. So add switch
> --set-upstream (-u) to do just that.
>
> Signed-off-by: Jeff King <peff@peff.net>
> Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
> ---
> Changes from v1:
> - Handle 'git push -u <remote> HEAD' correctly.
> - Add testsuite (thanks Peff), with some additional tests to test delete.
> - Modify documentation for push -u (thanks Matthieu Moy).
>
>  Documentation/git-push.txt |    9 +++++-
>  builtin-push.c             |    1 +
>  t/t5523-push-upstream.sh   |   64 ++++++++++++++++++++++++++++++++++++++++++++
>  transport.c                |   49 +++++++++++++++++++++++++++++++++
>  transport.h                |    1 +
>  5 files changed, 123 insertions(+), 1 deletions(-)
>  create mode 100755 t/t5523-push-upstream.sh
>
> diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
> index e3eb1e8..2a5394b 100644
> --- a/Documentation/git-push.txt
> +++ b/Documentation/git-push.txt
> @@ -10,7 +10,7 @@ SYNOPSIS
>  --------
>  [verse]
>  'git push' [--all | --mirror | --tags] [-n | --dry-run] [--receive-pack=<git-receive-pack>]
> -          [--repo=<repository>] [-f | --force] [-v | --verbose]
> +          [--repo=<repository>] [-f | --force] [-v | --verbose] [-u | --set-upstream]
>           [<repository> <refspec>...]
>
>  DESCRIPTION
> @@ -122,6 +122,13 @@ nor in any Push line of the corresponding remotes file---see below).
>        the name "origin" is used. For this latter case, this option
>        can be used to override the name "origin". In other words,
>        the difference between these two commands
> +
> +-u::
> +--set-upstream::
> +       For every branch that is up to date or successfully pushed, add
> +       upstream (tracking) reference, used by argument-less
> +       linkgit:git-pull[1] and other commands. For more information,
> +       see 'branch.<name>.merge' in linkgit:git-config[1].
>  +
>  --------------------------
>  git push public         #1
> diff --git a/builtin-push.c b/builtin-push.c
> index 28a26e7..75ddaf4 100644
> --- a/builtin-push.c
> +++ b/builtin-push.c
> @@ -218,6 +218,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
>                OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
>                OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", "receive pack program"),
>                OPT_STRING( 0 , "exec", &receivepack, "receive-pack", "receive pack program"),
> +               OPT_BIT('u', "set-upstream", &flags, "Set upstream for git pull", TRANSPORT_PUSH_SET_UPSTREAM),
>                OPT_END()
>        };
>
> diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh
> new file mode 100755
> index 0000000..e098d37
> --- /dev/null
> +++ b/t/t5523-push-upstream.sh
> @@ -0,0 +1,64 @@
> +#!/bin/sh
> +
> +test_description='push with --set-upstream'
> +. ./test-lib.sh
> +
> +test_expect_success 'setup bare parent' '
> +       git init --bare parent &&
> +       git remote add upstream 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.remote
> +        git config branch.$1.merge) >actual.$1
> +       test_cmp expect.$1 actual.$1
> +}
> +
> +test_expect_success 'push -u master:master' '
> +       git push -u upstream master:master &&
> +       check_config master upstream refs/heads/master
> +'
> +
> +test_expect_success 'push -u master:other' '
> +       git push -u upstream master:other &&
> +       check_config master upstream refs/heads/other
> +'
> +
> +test_expect_success 'push -u master2:master2' '
> +       git branch master2 &&
> +       git push -u upstream master2:master2 &&
> +       check_config master2 upstream refs/heads/master2
> +'
> +
> +test_expect_success 'push -u master2:other2' '
> +       git push -u upstream master2:other2 &&
> +       check_config master2 upstream refs/heads/other2
> +'
> +
> +test_expect_success 'push -u :master2' '
> +       git push -u upstream :master2 &&
> +       check_config master2 upstream refs/heads/other2
> +'
> +
> +test_expect_success 'push -u --all' '
> +       git branch all1 &&
> +       git branch all2 &&
> +       git push -u --all &&
> +       check_config all1 upstream refs/heads/all1 &&
> +       check_config all2 upstream refs/heads/all2
> +'
> +
> +test_expect_success 'push -u HEAD' '
> +       git checkout -b headbranch &&
> +       git push -u upstream HEAD &&
> +       check_config headbranch upstream refs/heads/headbranch
> +'
> +
> +test_done
> diff --git a/transport.c b/transport.c
> index b5332c0..e5b462b 100644
> --- a/transport.c
> +++ b/transport.c
> @@ -8,6 +8,7 @@
>  #include "bundle.h"
>  #include "dir.h"
>  #include "refs.h"
> +#include "branch.h"
>
>  /* rsync support */
>
> @@ -135,6 +136,47 @@ static void insert_packed_refs(const char *packed_refs, struct ref **list)
>        }
>  }
>
> +static void set_upstreams(struct transport *trans, struct ref *refs)
> +{
> +       struct ref *i;
> +       for (i = refs; i; i = i->next) {
> +               const char *localname;
> +               const char *tmp;
> +               const char *remotename;
> +               unsigned char sha[20];
> +               int flag = 0;
> +               /*
> +                * Check suitability for tracking. Must be successful /
> +                * alreay up-to-date ref create/modify (not delete).
> +                */
> +               if (i->status != REF_STATUS_OK &&
> +                       i->status != REF_STATUS_UPTODATE)
> +                       continue;
> +               if (!i->peer_ref)
> +                       continue;
> +               if (!i->new_sha1 || is_null_sha1(i->new_sha1))
> +                       continue;
> +
> +               /* Chase symbolic refs (mainly for HEAD). */
> +               localname = i->peer_ref->name;
> +               remotename = i->name;
> +               tmp = resolve_ref(localname, sha, 1, &flag);
> +               if (tmp && flag & REF_ISSYMREF &&
> +                       !prefixcmp(tmp, "refs/heads/"))
> +                       localname = tmp;
> +
> +               /* Both source and destination must be local branches. */
> +               if (!localname || prefixcmp(localname, "refs/heads/"))
> +                       continue;
> +               if (!remotename || prefixcmp(remotename, "refs/heads/"))
> +                       continue;
> +
> +               install_branch_config(BRANCH_CONFIG_VERBOSE,
> +                       localname + 11, trans->remote->name,
> +                       remotename);
> +       }
> +}
> +
>  static const char *rsync_url(const char *url)
>  {
>        return prefixcmp(url, "rsync://") ? skip_prefix(url, "rsync:") : url;
> @@ -974,6 +1016,10 @@ int transport_push(struct transport *transport,
>        verify_remote_names(refspec_nr, refspec);
>
>        if (transport->push) {
> +               /* Maybe FIXME. But no important transport uses this case. */
> +               if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
> +                       die("This transport does not support using --set-upstream");
> +
>                return transport->push(transport, refspec_nr, refspec, flags);
>        } else if (transport->push_refs) {
>                struct ref *remote_refs =
> @@ -1002,6 +1048,9 @@ int transport_push(struct transport *transport,
>                                        verbose | porcelain, porcelain,
>                                        nonfastforward);
>
> +               if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
> +                       set_upstreams(transport, remote_refs);
> +
>                if (!(flags & TRANSPORT_PUSH_DRY_RUN)) {
>                        struct ref *ref;
>                        for (ref = remote_refs; ref; ref = ref->next)
> diff --git a/transport.h b/transport.h
> index 97ba251..c4314dd 100644
> --- a/transport.h
> +++ b/transport.h
> @@ -91,6 +91,7 @@ struct transport {
>  #define TRANSPORT_PUSH_VERBOSE 16
>  #define TRANSPORT_PUSH_PORCELAIN 32
>  #define TRANSPORT_PUSH_QUIET 64
> +#define TRANSPORT_PUSH_SET_UPSTREAM 128
>
>  /* Returns a transport suitable for the url */
>  struct transport *transport_get(struct remote *, const char *);
> --
> 1.6.6.102.gd6f8f.dirty
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Rudolf Polzer· Jan 16, 2010, 18:13 UTC · re: Tay Ray Chuan · lore

Re: [PATCH v2] Add push --set-upstream

On Sat, Jan 16, 2010 at 09:00:30AM +0800, Tay Ray Chuan wrote:
Show 6 quoted lines
> Hi,
> 
> I'm adding people from the "git push --track" thread here, since this
> feature is related to what they want.
> 
> (sorry for any line-wrap mangling in the patch.)

Looks perfect to me, and if people want it, one could add the same option as an alias to the current --track option to the checkout and branch commands.

Show 7 quoted lines
> > +               /* Chase symbolic refs (mainly for HEAD). */
> > +               localname = i->peer_ref->name;
> > +               remotename = i->name;
> > +               tmp = resolve_ref(localname, sha, 1, &flag);
> > +               if (tmp && flag & REF_ISSYMREF &&
> > +                       !prefixcmp(tmp, "refs/heads/"))
> > +                       localname = tmp;
I would never have thought of that case - good catch.
Show 8 quoted lines
> > @@ -974,6 +1016,10 @@ int transport_push(struct transport *transport,
> >        verify_remote_names(refspec_nr, refspec);
> >
> >        if (transport->push) {
> > +               /* Maybe FIXME. But no important transport uses this case. */
> > +               if (flags & TRANSPORT_PUSH_SET_UPSTREAM)
> > +                       die("This transport does not support using --set-upstream");
> > +

That's ONE way to do it - and seriously, I don't know if anyone uses that transport :P

However, one possible improvement for this case would be setting ALL pushed refs as tracking if the push succeeded, and none otherwise.

Are new transports going to be added that use transport->push, or is that interface deprecated anyway?

Best regards,
Rudolf Polzer

← back to recent threads