Commit 5d7c1dab5252fee0ce211c15833dfd75027f6d1c

Stefan Sperling 2018-04-01T20:13:26

document checkout better and fix optional worktree arg

diff --git a/got/got.1 b/got/got.1
index d36fc50..12bc2ce 100644
--- a/got/got.1
+++ b/got/got.1
@@ -65,14 +65,22 @@ Display usage information.
 .Pp
 The commands are as follows:
 .Bl -tag -width checkout
-.It Cm checkout
+.It Cm checkout [ Fl p Ar path-prefix ] repository-path [ work-tree-path ]
 Copy files from a repository into a new work tree.
 The work tree may be restricted to a subset of the repository's tree
 hierarchy by specifying the
-.Fl p Ar prefix
+.Fl p Ar path-prefix
 option.
-In this case, only files beneath the specified directory prefix will
+In this case, only files beneath the specified prefix will
 be checked out.
+If the
+.Ar work tree path
+is not specified, either use the base name of the
+.Ar repository path ,
+or if a
+.Ar path prefix
+was specified use the base name of the
+.Ar path prefix .
 .\".It Cm status
 .\"Show current status of files.
 .It Cm log [ Fl p ] [ Fl c Ar commit ] [ Fl l Ar N ] [ Ar repository-path ]
diff --git a/got/got.c b/got/got.c
index cb7b07e..fffacf8 100644
--- a/got/got.c
+++ b/got/got.c
@@ -189,7 +189,10 @@ cmd_checkout(int argc, char *argv[])
 		cwd = getcwd(NULL, 0);
 		if (cwd == NULL)
 			err(1, "getcwd");
-		base = basename(repo_path);
+		if (path_prefix[0])
+			base = basename(path_prefix);
+		else
+			base = basename(repo_path);
 		if (base == NULL)
 			err(1, "basename");
 		dotgit = strstr(base, ".git");