allow references to be passed to '-c commit' options
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
diff --git a/got/got.1 b/got/got.1
index 59507d1..6bfe01e 100644
--- a/got/got.1
+++ b/got/got.1
@@ -143,7 +143,8 @@ reference will be used.
.It Fl c Ar commit
Check out files from the specified
.Ar commit .
-The expected argument is a commit ID SHA1 hash.
+The expected argument is a commit ID SHA1 hash or an existing reference
+which will be resolved to a commit ID.
An abbreviated hash argument will be expanded to a full SHA1 hash
automatically, provided the abbreviation is unique.
If this option is not specified, the most recent commit on the selected
@@ -201,7 +202,8 @@ This option requires that all paths in the work tree are updated.
.It Fl c Ar commit
Update the work tree to the specified
.Ar commit .
-The expected argument is a commit ID SHA1 hash.
+The expected argument is a commit ID SHA1 hash or an existing reference
+which will be resolved to a commit ID.
An abbreviated hash argument will be expanded to a full SHA1 hash
automatically, provided the abbreviation is unique.
If this option is not specified, the most recent commit on the work tree's
@@ -243,7 +245,8 @@ are as follows:
.It Fl c Ar commit
Start traversing history at the specified
.Ar commit .
-The expected argument is the name of a branch or a commit ID SHA1 hash.
+The expected argument is a commit ID SHA1 hash or an existing reference
+which will be resolved to a commit ID.
An abbreviated hash argument will be expanded to a full SHA1 hash
automatically, provided the abbreviation is unique.
If this option is not specified, default to the work tree's current branch
@@ -307,7 +310,8 @@ are as follows:
.It Fl c Ar commit
Start traversing history at the specified
.Ar commit .
-The expected argument is the name of a branch or a commit ID SHA1 hash.
+The expected argument is a commit ID SHA1 hash or an existing reference
+which will be resolved to a commit ID.
An abbreviated hash argument will be expanded to a full SHA1 hash
automatically, provided the abbreviation is unique.
.It Fl r Ar repository-path
@@ -341,7 +345,8 @@ are as follows:
.It Fl c Ar commit
List files and directories as they appear in the specified
.Ar commit .
-The expected argument is the name of a branch or a commit ID SHA1 hash.
+The expected argument is a commit ID SHA1 hash or an existing reference
+which will be resolved to a commit ID.
An abbreviated hash argument will be expanded to a full SHA1 hash
automatically, provided the abbreviation is unique.
.It Fl r Ar repository-path
diff --git a/got/got.c b/got/got.c
index b5341e1..a16ed7b 100644
--- a/got/got.c
+++ b/got/got.c
@@ -900,10 +900,19 @@ cmd_checkout(int argc, char *argv[])
}
if (commit_id_str) {
- struct got_object_id *commit_id;
- error = got_repo_match_object_id_prefix(&commit_id,
- commit_id_str, GOT_OBJ_TYPE_COMMIT, repo);
- if (error != NULL)
+ struct got_object_id *commit_id = NULL;
+ struct got_reference *ref;
+ error = got_ref_open(&ref, repo, commit_id_str, 0);
+ if (error == NULL) {
+ error = got_ref_resolve(&commit_id, repo, ref);
+ got_ref_close(ref);
+ } else {
+ if (error->code != GOT_ERR_NOT_REF)
+ goto done;
+ error = got_repo_match_object_id_prefix(&commit_id,
+ commit_id_str, GOT_OBJ_TYPE_COMMIT, repo);
+ }
+ if (error)
goto done;
error = check_linear_ancestry(commit_id,
got_worktree_get_base_commit_id(worktree), repo);
@@ -1108,9 +1117,19 @@ cmd_update(int argc, char *argv[])
if (error != NULL)
goto done;
} else {
- error = got_repo_match_object_id_prefix(&commit_id,
- commit_id_str, GOT_OBJ_TYPE_COMMIT, repo);
- if (error != NULL)
+ struct got_reference *ref;
+ error = got_ref_open(&ref, repo, commit_id_str, 0);
+ if (error == NULL) {
+ error = got_ref_resolve(&commit_id, repo, ref);
+ got_ref_close(ref);
+ }
+ else {
+ if (error->code != GOT_ERR_NOT_REF)
+ goto done;
+ error = got_repo_match_object_id_prefix(&commit_id,
+ commit_id_str, GOT_OBJ_TYPE_COMMIT, repo);
+ }
+ if (error)
goto done;
free(commit_id_str);
error = got_object_id_str(&commit_id_str, commit_id);
@@ -2015,9 +2034,18 @@ cmd_blame(int argc, char *argv[])
if (error != NULL)
goto done;
} else {
- error = got_repo_match_object_id_prefix(&commit_id,
- commit_id_str, GOT_OBJ_TYPE_COMMIT, repo);
- if (error != NULL)
+ struct got_reference *ref;
+ error = got_ref_open(&ref, repo, commit_id_str, 0);
+ if (error == NULL) {
+ error = got_ref_resolve(&commit_id, repo, ref);
+ got_ref_close(ref);
+ } else {
+ if (error->code != GOT_ERR_NOT_REF)
+ goto done;
+ error = got_repo_match_object_id_prefix(&commit_id,
+ commit_id_str, GOT_OBJ_TYPE_COMMIT, repo);
+ }
+ if (error)
goto done;
}
@@ -2247,9 +2275,18 @@ cmd_tree(int argc, char *argv[])
if (error != NULL)
goto done;
} else {
- error = got_repo_match_object_id_prefix(&commit_id,
- commit_id_str, GOT_OBJ_TYPE_COMMIT, repo);
- if (error != NULL)
+ struct got_reference *ref;
+ error = got_ref_open(&ref, repo, commit_id_str, 0);
+ if (error == NULL) {
+ error = got_ref_resolve(&commit_id, repo, ref);
+ got_ref_close(ref);
+ } else {
+ if (error->code != GOT_ERR_NOT_REF)
+ goto done;
+ error = got_repo_match_object_id_prefix(&commit_id,
+ commit_id_str, GOT_OBJ_TYPE_COMMIT, repo);
+ }
+ if (error)
goto done;
}