Commit 1cc14b9ffe9db23a9b9546d1ce7ab12237b4e35b

Stefan Sperling 2019-05-14T16:27:16

make 'got log' default to the current branch in a work tree

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);