Commit 993f033b6f1d781a4ba7970fec46915d08e53502

Stefan Sperling 2021-07-16T11:07:29

make 'got ref -d' print reference name and value like the new -X options do

diff --git a/got/got.c b/got/got.c
index 8dc4d8f..fb2f5bf 100644
--- a/got/got.c
+++ b/got/got.c
@@ -5277,13 +5277,27 @@ delete_ref(struct got_repository *repo, const char *refname)
 {
 	const struct got_error *err = NULL;
 	struct got_reference *ref;
+	struct got_object_id *id = NULL;
+	char *id_str = NULL;
 
 	err = got_ref_open(&ref, repo, refname, 0);
 	if (err)
 		return err;
 
+	err = got_ref_resolve(&id, repo, ref);
+	if (err)
+		goto done;
+	err = got_object_id_str(&id_str, id);
+	if (err)
+		goto done;
+
+	printf("Deleted %s: %s\n", got_ref_get_name(ref), id_str);
+
 	err = got_ref_delete(ref, repo);
+done:
 	got_ref_close(ref);
+	free(id);
+	free(id_str);
 	return err;
 }
 
diff --git a/regress/cmdline/cleanup.sh b/regress/cmdline/cleanup.sh
index 6290a77..72a0111 100755
--- a/regress/cmdline/cleanup.sh
+++ b/regress/cmdline/cleanup.sh
@@ -67,7 +67,8 @@ test_cleanup_unreferenced_loose_objects() {
 	# remove worktree's base commit reference, which points at the branch
 	wt_uuid=`(cd $testroot/wt && got info | grep 'UUID:' | \
 		cut -d ':' -f 2 | tr -d ' ')`
-	got ref -r $testroot/repo -d "refs/got/worktree/base-$wt_uuid"
+	got ref -r $testroot/repo -d "refs/got/worktree/base-$wt_uuid" \
+		> /dev/null
 
 	# cleanup -n should not remove any objects
 	ls -R $testroot/repo/.git/objects > $testroot/objects-before
diff --git a/regress/cmdline/fetch.sh b/regress/cmdline/fetch.sh
index fa4ff05..5292407 100755
--- a/regress/cmdline/fetch.sh
+++ b/regress/cmdline/fetch.sh
@@ -939,7 +939,7 @@ test_fetch_headref_deleted_locally() {
 		return 1
 	fi
 
-	got ref -r $testroot/repo-clone -d refs/remotes/origin/HEAD
+	got ref -r $testroot/repo-clone -d refs/remotes/origin/HEAD > /dev/null
 
 	got fetch -q -r $testroot/repo-clone
 	ret="$?"
diff --git a/regress/cmdline/rebase.sh b/regress/cmdline/rebase.sh
index d590abf..6d5ebb9 100755
--- a/regress/cmdline/rebase.sh
+++ b/regress/cmdline/rebase.sh
@@ -912,7 +912,7 @@ test_rebase_forward() {
 	# commit 3907e11dceaae2ca7f8db79c2af31794673945ad (origin/master)
 	# commit ffcffcd102cf1af6572fbdbb4cf07a0f1fd2d840 (master)
 	# commit 87a6a8a2263a15b61c016ff1720b24741d455eb5
-	(cd $testroot/repo && got ref -d master)
+	(cd $testroot/repo && got ref -d master >/dev/null)
 	(cd $testroot/repo && got ref -c $commit1 refs/heads/master)
 	(cd $testroot/repo && got ref -c $commit2 refs/remotes/origin/master)
 
diff --git a/regress/cmdline/ref.sh b/regress/cmdline/ref.sh
index 0093198..98a9f97 100755
--- a/regress/cmdline/ref.sh
+++ b/regress/cmdline/ref.sh
@@ -209,6 +209,14 @@ test_ref_delete() {
 		test_done "$testroot" "$ret"
 		return 1
 	fi
+	echo "Deleted refs/heads/ref2: $commit_id" > $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
 
 	got ref -l -r $testroot/repo > $testroot/stdout
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
@@ -263,7 +271,7 @@ test_ref_delete() {
 		return 1
 	fi
 
-	got ref -r $testroot/repo -d master
+	got ref -r $testroot/repo -d master >/dev/null
 
 	got ref -l -r $testroot/repo > $testroot/stdout
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected