commit - b7165be31e6f0e737f415f628abe4cd4e7e1a53a
commit + 52185f702d047f6581c79bd99a14e3f1b84f2c5c
blob - ff123af7b716478317257a00a538cf50668c4311
blob + 812afe04bbe182c7c435c0de9361ff3d7feec15b
--- tog/tog.c
+++ tog/tog.c
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)
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);
goto done;
error = view_loop(view);
done:
+ free(repo_path);
free(commit_id);
if (commit)
got_object_commit_close(commit);