Commit Diff


commit - 440789268f3cd17dbbc1bb2bc431afdf36cf8302
commit + 38c5cf99cb18843b733401b41376c563a266641f
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 - d012eecaafaa3a264b4fc0b04e4b5a8abddaf9a1
blob + 53059582d7c705f7fe29bdb5227476bbceaac22e
--- 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) {