Commit 9c4b8182fcfabf42c6dc904dfccd3c4aa9bb4bcf

Stefan Sperling 2019-01-02T16:11:39

print new base commit ID when update is done

diff --git a/got/got.c b/got/got.c
index 746cf51..74fa300 100644
--- a/got/got.c
+++ b/got/got.c
@@ -394,13 +394,15 @@ cmd_update(int argc, char *argv[])
 	struct got_worktree *worktree = NULL;
 	char *worktree_path = NULL;
 	struct got_object_id *commit_id = NULL;
-	const char *commit_id_str = NULL;
+	char *commit_id_str = NULL;
 	int ch;
 
 	while ((ch = getopt(argc, argv, "c:")) != -1) {
 		switch (ch) {
 		case 'c':
-			commit_id_str = optarg;
+			commit_id_str = strdup(optarg);
+			if (commit_id_str == NULL)
+				return got_error_from_errno();
 			break;
 		default:
 			usage();
@@ -447,6 +449,9 @@ cmd_update(int argc, char *argv[])
 		error = got_ref_resolve(&commit_id, repo, head_ref);
 		if (error != NULL)
 			goto done;
+		error = got_object_id_str(&commit_id_str, commit_id);
+		if (error != NULL)
+			goto done;
 	} else {
 		error = got_object_resolve_id_str(&commit_id, repo,
 		    commit_id_str);
@@ -470,9 +475,12 @@ cmd_update(int argc, char *argv[])
 	    update_progress, NULL, checkout_cancel, NULL);
 	if (error != NULL)
 		goto done;
+
+	printf("Updated to commit %s\n", commit_id_str);
 done:
 	free(worktree_path);
 	free(commit_id);
+	free(commit_id_str);
 	return error;
 }
 
diff --git a/regress/cmdline/common.sh b/regress/cmdline/common.sh
index 4fb24d6..d585d9b 100644
--- a/regress/cmdline/common.sh
+++ b/regress/cmdline/common.sh
@@ -26,6 +26,12 @@ function git_commit
 	(cd $repo && git commit -q -a "$@")
 }
 
+function git_show_head
+{
+	local repo="$1"
+	(cd $repo && git show --no-patch --pretty='format:%H')
+}
+
 function make_test_tree
 {
 	repo="$1"
diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh
index 416b75e..736d20e 100755
--- a/regress/cmdline/update.sh
+++ b/regress/cmdline/update.sh
@@ -29,6 +29,9 @@ function test_update_basic {
 	git_commit $testroot/repo -m "modified alpha"
 
 	echo "U  alpha" > $testroot/stdout.expected
+	echo -n "Updated to commit " >> $testroot/stdout.expected
+	git_show_head $testroot/repo >> $testroot/stdout.expected
+	echo >> $testroot/stdout.expected
 
 	(cd $testroot/wt && got update > $testroot/stdout)