Skip to contentSkip to conversation

transport: respect verbosity when setting upstream

PATCH In review Øystein Walle 3 participants 4 messages Apr 15, 2021 – Apr 16, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 transport: respect verbosity when setting upstream

A command such as git push -qu origin feature will print "Branch 'feature' set up to track remote branch 'feature' from 'origin'." even when --quiet is passed. In this case it's because install_branch_config() is always called with BRANCH_CONFIG_VERBOSE.

struct transport keeps track of the desired verbosity. Fix the above issue by passing BRANCH_CONFIG_VERBOSE conditionally based on that.

---
 t/t5523-push-upstream.sh |  7 +++++++
 transport.c              | 10 +++++-----
 2 files changed, 12 insertions(+), 5 deletions(-)
t/t5523-push-upstream.sh +7 -0
index 9fbe7f784d..fdb4292056 100755
@@ -119,4 +119,11 @@ test_expect_success TTY 'quiet push' '
 	test_must_be_empty output
 '
 
+test_expect_success TTY 'quiet push -u' '
+	ensure_fresh_upstream &&
+
+	test_terminal git push --quiet -u --no-progress upstream main 2>&1 | tee output &&
+	test_must_be_empty output
+'
+
 test_done
transport.c +5 -5
index ef66e73090..62b6eeed21 100644
@@ -108,11 +108,11 @@ static void set_upstreams(struct transport *transport, struct ref *refs,
 		if (!remotename || !starts_with(remotename, "refs/heads/"))
 			continue;
 
-		if (!pretend)
-			install_branch_config(BRANCH_CONFIG_VERBOSE,
-				localname + 11, transport->remote->name,
-				remotename);
-		else
+		if (!pretend) {
+			int flag = transport->verbose < 0 ? 0 : BRANCH_CONFIG_VERBOSE;
+			install_branch_config(flag, localname + 11,
+				transport->remote->name, remotename);
+		} else if (transport->verbose >= 0)
 			printf(_("Would set upstream of '%s' to '%s' of '%s'\n"),
 				localname + 11, remotename + 11,
 				transport->remote->name);
Signature · 1 line
2.20.1
#1 lore raw
Quoted 12 lines · Øystein Walle

A command such as git push -qu origin feature will print "Branch 'feature' set up to track remote branch 'feature' from 'origin'." even when --quiet is passed. In this case it's because install_branch_config() is always called with BRANCH_CONFIG_VERBOSE.

struct transport keeps track of the desired verbosity. Fix the above issue by passing BRANCH_CONFIG_VERBOSE conditionally based on that.

---

t/t5523-push-upstream.sh test_expect_success TTY 'quiet push' ' · line 124

Quoted 6 lines
t/t5523-push-upstream.sh +6 -0
@@ -119,4 +119,11 @@ test_expect_success TTY 'quiet push' '
+test_expect_success TTY 'quiet push -u' '
+       ensure_fresh_upstream &&
+
+       test_terminal git push --quiet -u --no-progress upstream main 2>&1 | tee output &&
+       test_must_be_empty output
+'

I wondered why you used tee here since it adds no value (as far as I can tell), but I see that you copied it from the test preceding this one. So... [intentionally left blank]

#2 lore raw
Quoted 3 lines · Eric Sunshine

I wondered why you used tee here since it adds no value (as far as I can tell), but I see that you copied it from the test preceding this one. So... [intentionally left blank]

Indeed, I wondered about that too; it seems a plain redirection will do the trick. But a mix of laziness and not second-guessing others' work made me leave it as it is.

Øsse

#3 lore raw
Quoted 9 lines · Øystein Walle
Quoted 3 lines · Eric Sunshine

I wondered why you used tee here since it adds no value (as far as I can tell), but I see that you copied it from the test preceding this one. So... [intentionally left blank]

Indeed, I wondered about that too; it seems a plain redirection will do the trick. But a mix of laziness and not second-guessing others' work made me leave it as it is.

Let's agree to mark it as #leftoverbits then?

Thanks for a fix, additional tests, and a good review.