commit cffc0aa45ba6718abca889b1e53198b6e9faea8c from: Stefan Sperling date: Tue Feb 05 17:15:49 2019 UTC make 'got log' function inside a work tree commit - f0559eb5490cba70e142360c71d5ab1863eab10e commit + cffc0aa45ba6718abca889b1e53198b6e9faea8c blob - b4eef2f832a548ecc2f563f7ce8b2bf13d0eddcb blob + 9363f9a78c59dc1c3863a5a0450aeba950e71e2b --- got/got.c +++ got/got.c @@ -758,6 +758,7 @@ cmd_log(int argc, char *argv[]) { const struct got_error *error; struct got_repository *repo = NULL; + struct got_worktree *worktree = NULL; struct got_commit_object *commit = NULL; struct got_object_id *id = NULL; char *repo_path = NULL, *path = NULL, *cwd = NULL, *in_repo_path = NULL; @@ -824,12 +825,17 @@ cmd_log(int argc, char *argv[]) error = got_error_from_errno(); goto done; } + + error = got_worktree_open(&worktree, cwd); + if (error && error->code != GOT_ERR_NOT_WORKTREE) + goto done; + error = NULL; + + repo_path = worktree ? + strdup(got_worktree_get_repo_path(worktree)) : strdup(cwd); if (repo_path == NULL) { - repo_path = strdup(cwd); - if (repo_path == NULL) { - error = got_error_from_errno(); - goto done; - } + error = got_error_from_errno(); + goto done; } error = apply_unveil(repo_path, NULL); @@ -919,6 +925,8 @@ done: free(repo_path); free(cwd); free(id); + if (worktree) + got_worktree_close(worktree); if (repo) { const struct got_error *repo_error; repo_error = got_repo_close(repo);