Commit Diff


commit - a3a0e34e98c4f91a4b8fe53e24f82833a72e40a1
commit + fe66084b58b0c7faa4fa6510bd049745023c6635
blob - 60b728087babd46e2f9a0783a6419cac467c8bac
blob + 6b7c7bd27c8c62a8167e54f6c70ee316583c9367
--- got/got.c
+++ got/got.c
@@ -11879,28 +11879,29 @@ cmd_cat(int argc, char *argv[])
 		error = got_error_from_errno("getcwd");
 		goto done;
 	}
-	error = got_worktree_open(&worktree, cwd);
-	if (error && error->code != GOT_ERR_NOT_WORKTREE)
-		goto done;
-	if (worktree) {
-		if (repo_path == NULL) {
+
+	if (repo_path == NULL) {
+		error = got_worktree_open(&worktree, cwd);
+		if (error && error->code != GOT_ERR_NOT_WORKTREE)
+			goto done;
+		if (worktree) {
 			repo_path = strdup(
 			    got_worktree_get_repo_path(worktree));
 			if (repo_path == NULL) {
 				error = got_error_from_errno("strdup");
 				goto done;
 			}
-		}
 
-		/* Release work tree lock. */
-		got_worktree_close(worktree);
-		worktree = NULL;
+			/* Release work tree lock. */
+			got_worktree_close(worktree);
+			worktree = NULL;
+		}
 	}
 
 	if (repo_path == NULL) {
-		repo_path = getcwd(NULL, 0);
+		repo_path = strdup(cwd);
 		if (repo_path == NULL)
-			return got_error_from_errno("getcwd");
+			return got_error_from_errno("strdup");
 	}
 
 	error = got_repo_open(&repo, repo_path, NULL);