Commit Diff


commit - 29e0594f3da103f1ece51fe40ba09faa1c691972
commit + a091f71abcb1f9a1860ae417667215c2a6d00edc
blob - c317c15e1db828dea457cd13aa02cfba0c723b80
blob + 337e09341fedfe2c803c97a519f332a08a772cab
--- 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);