switch 'tog tree' repository path argument to a new -r option
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
diff --git a/tog/tog.1 b/tog/tog.1
index 36e3560..1cca129 100644
--- a/tog/tog.1
+++ b/tog/tog.1
@@ -250,11 +250,8 @@ Use the repository at the specified path.
If not specified, assume the repository is located at or above the current
working directory.
.El
-.It Cm tree Oo Fl c Ar commit Oc Op Ar repository-path
+.It Cm tree Oo Fl c Ar commit Oc Oo Fl r Ar repository-path Oc
Display the repository tree.
-If the
-.Ar repository path
-is omitted, assume the repository is located in the current working directory.
.Pp
Displayed tree entries may carry one of the following trailing annotations:
.Bl -column YXZ description
@@ -308,6 +305,13 @@ Start traversing history at the specified
The expected argument is the name of a branch or a commit ID SHA1 hash.
An abbreviated hash argument will be expanded to a full SHA1 hash
automatically, provided the abbreviation is unique.
+.It Fl r Ar repository-path
+Use the repository at the specified path.
+If not specified, assume the repository is located at or above the current
+working directory.
+If this directory is a
+.Xr got 1
+work tree, use the repository path associated with this work tree.
.El
.El
.Sh ENVIRONMENT
diff --git a/tog/tog.c b/tog/tog.c
index 9618b61..ca4cead 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -5156,7 +5156,7 @@ __dead static void
usage_tree(void)
{
endwin();
- fprintf(stderr, "usage: %s tree [-c commit] [repository-path]\n",
+ fprintf(stderr, "usage: %s tree [-c commit] [-r repository-path]\n",
getprogname());
exit(1);
}
@@ -5183,11 +5183,17 @@ cmd_tree(int argc, char *argv[])
err(1, "pledge");
#endif
- while ((ch = getopt(argc, argv, "c:")) != -1) {
+ while ((ch = getopt(argc, argv, "c:r:")) != -1) {
switch (ch) {
case 'c':
commit_id_arg = optarg;
break;
+ case 'r':
+ repo_path = realpath(optarg, NULL);
+ if (repo_path == NULL)
+ return got_error_from_errno2("realpath",
+ optarg);
+ break;
default:
usage_tree();
/* NOTREACHED */
@@ -5197,7 +5203,10 @@ cmd_tree(int argc, char *argv[])
argc -= optind;
argv += optind;
- if (argc == 0) {
+ if (argc != 0)
+ usage_tree();
+
+ if (repo_path == NULL) {
struct got_worktree *worktree;
char *cwd = getcwd(NULL, 0);
if (cwd == NULL)
@@ -5205,6 +5214,8 @@ cmd_tree(int argc, char *argv[])
error = got_worktree_open(&worktree, cwd);
if (error && error->code != GOT_ERR_NOT_WORKTREE)
goto done;
+ else
+ error = NULL;
if (worktree) {
free(cwd);
repo_path =
@@ -5216,12 +5227,7 @@ cmd_tree(int argc, char *argv[])
error = got_error_from_errno("strdup");
goto done;
}
- } else if (argc == 1) {
- repo_path = realpath(argv[0], NULL);
- if (repo_path == NULL)
- return got_error_from_errno2("realpath", argv[0]);
- } else
- usage_tree();
+ }
init_curses();