make 'got log' default to the current branch in a work tree
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
diff --git a/got/got.1 b/got/got.1
index e31268e..8412b6f 100644
--- a/got/got.1
+++ b/got/got.1
@@ -171,6 +171,8 @@ Start traversing history at the specified
.Ar commit .
The expected argument is the name of a branch or a SHA1 hash which corresponds
to a commit object.
+If this option is not specified, default to the work tree's current branch
+if invoked in a work tree, or to the repository's HEAD reference.
.It Fl C Ar number
Set the number of context lines shown in diffs with
.Fl p .
diff --git a/got/got.c b/got/got.c
index bdb8179..5576a94 100644
--- a/got/got.c
+++ b/got/got.c
@@ -954,7 +954,7 @@ cmd_log(int argc, char *argv[])
err(1, "pledge");
#endif
- while ((ch = getopt(argc, argv, "pc:C:l:fr:")) != -1) {
+ while ((ch = getopt(argc, argv, "b:pc:C:l:fr:")) != -1) {
switch (ch) {
case 'p':
show_patch = 1;
@@ -1044,7 +1044,9 @@ cmd_log(int argc, char *argv[])
if (start_commit == NULL) {
struct got_reference *head_ref;
- error = got_ref_open(&head_ref, repo, GOT_REF_HEAD, 0);
+ error = got_ref_open(&head_ref, repo,
+ worktree ? got_worktree_get_head_ref_name(worktree)
+ : GOT_REF_HEAD, 0);
if (error != NULL)
return error;
error = got_ref_resolve(&id, repo, head_ref);