git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Jeff King <peff@peff.net>
Date
Jan 15, 2010, 17:17 UTC
Message-ID
<20100115171745.GB2115@coredump.intra.peff.net>
In-Reply-To
<1263573407-13642-1-git-send-email-ilari.liusvaara@elisanet.fi>
On Fri, Jan 15, 2010 at 06:36:47PM +0200, Ilari Liusvaara 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.
Huzzah, finally this feature is done right. I even like the name.
Show 5 quoted lines
>  Documentation/git-push.txt |    8 +++++++-
>  builtin-push.c             |    1 +
>  transport.c                |   35 +++++++++++++++++++++++++++++++++++
>  transport.h                |    1 +
>  4 files changed, 44 insertions(+), 1 deletions(-)

No tests. But since in writing this you have crossed an item off of my long-term todo, I feel obliged to help out by providing some. :)

The patch below is squash-able, but note that the final test, "git push -u HEAD" is marked as broken. We should probably support that. I suspect is is an issue of dereferencing symrefs before doing the prefixcmp("refs/heads/", ...) but I haven't checked yet.

diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh
new file mode 100755
index 0000000..e977553
--- /dev/null
+++ b/t/t5523-push-upstream.sh
@@ -0,0 +1,48 @@
+#!/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 --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_failure 'push -u HEAD' '
+	git checkout -b headbranch &&
+	git push -u upstream HEAD &&
+	check_config headbranch upstream refs/heads/headbranch
+'
+
+test_done
Previous: Junio C HamanoNext: Jeff King
Message 5 of 9 in “Add push --set-upstream”
  1. Add push --set-upstreamIlari Liusvaara, Jan 15, 2010
  2. Matthieu MoyJan 15, 2010
  3. Johannes SchindelinJan 15, 2010
  4. Junio C HamanoJan 15, 2010
  5. Jeff KingJan 15, 2010
  6. Jeff KingJan 15, 2010
  7. Ilari LiusvaaraJan 15, 2010
  8. Jeff KingJan 15, 2010
  9. Junio C HamanoJan 15, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.