make 'tog tree' function in a work tree
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
diff --git a/tog/tog.c b/tog/tog.c
index ff123af..812afe0 100644
--- a/tog/tog.c
+++ b/tog/tog.c
@@ -3459,9 +3459,24 @@ cmd_tree(int argc, char *argv[])
argv += optind;
if (argc == 0) {
- repo_path = getcwd(NULL, 0);
- if (repo_path == NULL)
+ struct got_worktree *worktree;
+ char *cwd = getcwd(NULL, 0);
+ if (cwd == NULL)
return got_error_from_errno();
+ error = got_worktree_open(&worktree, cwd);
+ if (error && error->code != GOT_ERR_NOT_WORKTREE)
+ goto done;
+ if (worktree) {
+ free(cwd);
+ repo_path =
+ strdup(got_worktree_get_repo_path(worktree));
+ got_worktree_close(worktree);
+ } else
+ repo_path = cwd;
+ if (repo_path == NULL) {
+ error = got_error_from_errno();
+ goto done;
+ }
} else if (argc == 1) {
repo_path = realpath(argv[0], NULL);
if (repo_path == NULL)
@@ -3471,12 +3486,11 @@ cmd_tree(int argc, char *argv[])
error = apply_unveil(repo_path, NULL);
if (error)
- return error;
+ goto done;
error = got_repo_open(&repo, repo_path);
- free(repo_path);
if (error != NULL)
- return error;
+ goto done;
if (commit_id_arg == NULL)
error = get_head_commit_id(&commit_id, repo);
@@ -3505,6 +3519,7 @@ cmd_tree(int argc, char *argv[])
goto done;
error = view_loop(view);
done:
+ free(repo_path);
free(commit_id);
if (commit)
got_object_commit_close(commit);