print new base commit ID when update is done
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
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)