Commit 1bd76734ce8e567c3f156533dc1af31878bd5a65

Stefan Sperling 2021-08-26T13:41:59

fix the output of 'got send -d' upon success Previous output was: Already up-to-date New output is: Server has deleted refs/heads/branch Check this behavour in the related regression test.

diff --git a/lib/send.c b/lib/send.c
index 52f062e..52892c3 100644
--- a/lib/send.c
+++ b/lib/send.c
@@ -742,6 +742,13 @@ got_send_pack(const char *remote_name, struct got_pathlist_head *branch_names,
 			refs_to_send++;
 	}
 
+	/* Account for any existing references we are going to delete. */
+	TAILQ_FOREACH(pe, delete_branches, entry) {
+		const char *branchname = pe->path;
+		if (find_their_ref(&their_refs, branchname))
+			refs_to_send++;
+	}
+
 	if (refs_to_send == 0) {
 		got_privsep_send_stop(imsg_sendfds[0]);
 		goto done;
diff --git a/regress/cmdline/send.sh b/regress/cmdline/send.sh
index e05bcb5..d8ab1ac 100755
--- a/regress/cmdline/send.sh
+++ b/regress/cmdline/send.sh
@@ -353,14 +353,30 @@ EOF
 		return 1
 	fi
 
-	got send -q -r $testroot/repo -d refs/heads/branch2 origin \
-		> $testroot/stdout 2> $testroot/stderr
+	got send -r $testroot/repo -d refs/heads/branch2 origin \
+		> $testroot/stdout.raw 2>$testroot/stderr
 	ret="$?"
 	if [ "$ret" != "0" ]; then
 		echo "got send command failed unexpectedly" >&2
 		test_done "$testroot" "$ret"
 		return 1
 	fi
+	tr -d '\r' < $testroot/stdout.raw > $testroot/stdout
+
+	echo 'Connecting to "origin" 127.0.0.1' > $testroot/stdout.expected
+	echo -n "packing 0 references; 0 objects; deltify: 0%; " \
+		>> $testroot/stdout.expected
+	echo "uploading pack:     32B 100%" >> $testroot/stdout.expected
+	echo "Server has deleted refs/heads/branch2" \
+		>> $testroot/stdout.expected
+
+	cmp -s $testroot/stdout $testroot/stdout.expected
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		diff -u $testroot/stdout.expected $testroot/stdout
+		test_done "$testroot" "$ret"
+		return 1
+	fi
 
 	# branchX exists in neither repository
 	got send -q -r $testroot/repo -d refs/heads/branchX origin \