mbox series

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

Message ID 20211209101550.19582-1-chakrabortyabhradeep79@gmail.com (mailing list archive)
Headers show
Series making --set-upstream have default arguments | expand

Message

Abhradeep Chakraborty Dec. 9, 2021, 10:15 a.m. UTC
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
     +'