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

[PATCH v3 0/1] making --set-upstream have default arguments

From
Abhradeep Chakraborty <chakrabortyabhradeep79@gmail.com>
Date
Dec 9, 2021, 10:15 UTC
Message-ID
<20211209101550.19582-1-chakrabortyabhradeep79@gmail.com>
In-Reply-To
<20211207182300.4361-1-chakrabortyabhradeep79@gmail.com>

This patch series tries to make the 'set-upstream' option for 'git push' have default arguments.

In v0: argumentless 'git push -u' was blindly passing default remote name and current branch's name as argv[0] and argv[1] respectively. This was affecting `push.default` setting.

From v1: The default remote is still used for the <repository> value. But <refspec> depends on the current push configurations. If `push.default`='matching', it pushes to the upstream as it should and sets upstream respectively. For other values of 'push.default', it pushes to the remote branch with the same name as the current branch and sets that branch as the upstream.

In this version, the tests are improved.
Abhradeep Chakraborty (1):
  push: make '-u' have default arguments
 Documentation/git-push.txt | 10 +++++
 builtin/push.c             | 11 ++++-
 t/t5523-push-upstream.sh   | 87 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 106 insertions(+), 2 deletions(-)
Range-diff against v2:
1:  6567327900 ! 1:  376ba6cb8f push: make '-u' have default arguments
    @@ Documentation/git-push.txt: Specifying `--no-force-if-includes` disables this be
     +If `push.default` is set to `matching`, all remote branches to which
     +local branches pushed, will be set as upstream of respective local
     +branches. For all other values of `push.default`, current branch's
    -+`<refspec>` will be used as the `<refspec>`.
    ++refspec will be used as the `<refspec>`.
      
      --[no-]thin::
      	These options are passed to linkgit:git-send-pack[1]. A thin transfer
    @@ t/t5523-push-upstream.sh: test_expect_success 'push -u :topic_2' '
      '
      
     +default_u_setup() {
    -+	git checkout main
    -+	remote=$(git config --get branch.main.remote)
    -+	if [ ! -z "$remote" ]; then
    -+		git branch --unset-upstream
    -+	fi
    -+	git config push.default $1
    -+	git config remote.pushDefault upstream
    ++	git checkout main &&
    ++	test_might_fail	git branch --unset-upstream &&
    ++	test_config push.default $1 &&
    ++	test_config remote.pushDefault upstream
     +}
     +
    -+test_expect_success 'push -u with push.default=simple' '
    -+	default_u_setup simple &&
    -+	git push -u &&
    -+	check_config main upstream refs/heads/main &&
    -+	git push -u upstream main:other &&
    -+	git push -u &&
    -+	check_config main upstream refs/heads/main
    -+'
    -+
    -+test_expect_success 'push -u with push.default=current' '
    -+	default_u_setup current &&
    -+	git push -u &&
    -+	check_config main upstream refs/heads/main &&
    -+	git push -u upstream main:other &&
    -+	git push -u &&
    -+	check_config main upstream refs/heads/main
    -+'
    -+
    -+test_expect_success 'push -u with push.default=upstream' '
    -+	default_u_setup upstream &&
    -+	git push -u &&
    -+	check_config main upstream refs/heads/main &&
    -+	git push -u upstream main:other &&
    -+	git push -u &&
    -+	check_config main upstream refs/heads/main
    -+'
    ++for i in simple current upstream nothing
    ++do
    ++	test_expect_success 'push -u with push.default=$i' '
    ++		default_u_setup $i &&
    ++		git push -u &&
    ++		check_config main upstream refs/heads/main &&
    ++		git push -u upstream main:other &&
    ++		git push -u &&
    ++		check_config main upstream refs/heads/main
    ++	'
    ++done
     +
     +check_empty_config() {
    -+	test_expect_code 1 git config "branch.$1.remote"
    ++	test_expect_code 1 git config "branch.$1.remote" &&
     +	test_expect_code 1 git config "branch.$1.merge"
     +}
     +
    @@ t/t5523-push-upstream.sh: test_expect_success 'push -u :topic_2' '
     +	check_empty_config test_u
     +'
     +
    -+test_expect_success 'push -u with push.default=nothing' '
    -+	default_u_setup nothing &&
    -+	git push -u &&
    -+	check_config main upstream refs/heads/main &&
    -+	git push -u upstream main:other &&
    -+	git push -u &&
    -+	check_config main upstream refs/heads/main
    -+'
    -+
     +test_expect_success 'push -u --dry-run' '
     +	git checkout main &&
     +	git push -u upstream main:other &&
    @@ t/t5523-push-upstream.sh: test_expect_success TTY 'progress messages go to tty'
     +test_expect_success TTY 'progress messages go to tty with default -u' '
     +	ensure_fresh_upstream &&
     +
    -+	test_terminal git push -u >out 2>err &&
    ++	test_terminal git push -u 2>err &&
     +	test_i18ngrep "Writing objects" err
     +'
     +
    @@ t/t5523-push-upstream.sh: test_expect_success 'progress messages do not go to no
      	test_i18ngrep ! "Writing objects" err
      '
      
    -+test_expect_success 'progress messagesdo not go to non-tty (default -u)' '
    ++test_expect_success 'progress messages do not go to non-tty (default -u)' '
     +	ensure_fresh_upstream &&
     +
     +	# skip progress messages, since stderr is non-tty
    -+	git push -u >out 2>err &&
    ++	git push -u 2>err &&
     +	test_i18ngrep ! "Writing objects" err
     +'
     +
    @@ t/t5523-push-upstream.sh: test_expect_success 'progress messages go to non-tty (
     +	ensure_fresh_upstream &&
     +
     +	# force progress messages to stderr, even though it is non-tty
    -+	git push -u --progress >out 2>err &&
    ++	git push -u --progress 2>err &&
     +	test_i18ngrep "Writing objects" err
     +'
     +
    @@ t/t5523-push-upstream.sh: test_expect_success TTY 'push -q suppresses progress'
     +test_expect_success TTY 'push -q suppresses progress (with default -u)' '
     +	ensure_fresh_upstream &&
     +
    -+	test_terminal git push -u -q >out 2>err &&
    ++	test_terminal git push -u -q 2>err &&
     +	test_i18ngrep ! "Writing objects" err
     +'
     +
    @@ t/t5523-push-upstream.sh: test_expect_success TTY 'push --no-progress suppresses
     +test_expect_success TTY 'push --no-progress suppresses progress (default -u)' '
     +	ensure_fresh_upstream &&
     +
    -+	test_terminal git push -u --no-progress >out 2>err &&
    ++	test_terminal git push -u --no-progress 2>err &&
     +	test_i18ngrep ! "Unpacking objects" err &&
     +	test_i18ngrep ! "Writing objects" err
     +'
-- 
2.34.1
Previous: Abhradeep ChakrabortyNext: Abhradeep Chakraborty
Message 15 of 21 in “making --set-upstream have default arguments”
  1. 0/1 making --set-upstream have default argumentsAbhradeep Chakraborty, Dec 2, 2021
  2. 1/1 push: make '-u' have default argumentsAbhradeep Chakraborty, Dec 2, 2021
  3. Junio C HamanoDec 2, 2021
  4. Abhradeep ChakrabortyDec 3, 2021
  5. Junio C HamanoDec 3, 2021
  6. Abhradeep ChakrabortyDec 3, 2021
  7. Philip OakleyDec 3, 2021
  8. Abhradeep ChakrabortyDec 3, 2021
  9. Philip OakleyDec 3, 2021
  10. Abhradeep ChakrabortyDec 3, 2021
  11. 0/1 making --set-upstream have default argumentsAbhradeep Chakraborty, Dec 7, 2021
  12. 1/1 push: make '-u' have default argumentsAbhradeep Chakraborty, Dec 7, 2021
  13. Eric SunshineDec 7, 2021
  14. Abhradeep ChakrabortyDec 8, 2021
  15. 0/1 making --set-upstream have default argumentsAbhradeep Chakraborty, Dec 9, 2021
  16. 1/1 push: make '-u' have default argumentsAbhradeep Chakraborty, Dec 9, 2021
  17. 0/1 making --set-upstream have default argumentsAbhradeep Chakraborty, Jan 1, 2022
  18. 1/1 push: make 'set-upstream' have dafault argumentsAbhradeep Chakraborty, Jan 1, 2022
  19. Junio C HamanoJan 4, 2022
  20. Abhradeep ChakrabortyJan 4, 2022
  21. Junio C HamanoJan 4, 2022

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.