Commit Diff


commit - e1ecf949b99fb9205921814421b1f52c0f2db56f
commit + ddb2df58a374b7058f0d3044c25b821680bd3345
blob - fdb4ef70a58be2c0ebaee1bc320ee9ba9a5c82fe
blob + ff51dcada6ea9946aed98884cc5f0bdaa65a5164
--- got/got.1
+++ got/got.1
@@ -396,8 +396,10 @@ from the remote repository's
 reference namespace.
 This option may be specified multiple times to build a list of branches
 to fetch.
-If this option is not specified, a branch resolved via the remote
-repository's HEAD reference will be fetched.
+If this option is not specified, the work tree's current branch
+will be fetched if invoked within a work tree,
+otherwise a branch resolved via the remote repository's HEAD reference
+will be fetched.
 Cannot be used together with the
 .Fl a
 option.
blob - 29a58f762f6daee7971bdeac8f303124c5d6f1f2
blob + 8b62a11fd84c9ac104aee2c98521c54f0ea943ec
--- got/got.c
+++ got/got.c
@@ -2442,6 +2442,12 @@ cmd_fetch(int argc, char *argv[])
 					break;
 				}
 			}
+		}
+		if (TAILQ_EMPTY(&wanted_branches)) {
+			error = got_pathlist_append(&wanted_branches,
+			    got_worktree_get_head_ref_name(worktree), NULL);
+			if (error)
+				goto done;
 		}
 	}
 	if (remote == NULL) {