Commit Diff


commit - db32465dae89b65a67ccba625a37217bb5354f15
commit + 74283ab8e59cdc12bc4adb3d2037f37df510bf1f
blob - 36e35600546ee630e56c145e5782f025e0bd5e9b
blob + 1cca12979be126c0b7f73441feaa69ebf0e7ea73
--- tog/tog.1
+++ 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
blob - 9618b61537be4967b0ef86f1793eb3479d5a0fb8
blob + ca4cead9c16398f8662b7c5b5962f54b0a506979
--- tog/tog.c
+++ 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,10 +5183,16 @@ 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();
@@ -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();