Skip to content

Commit

Permalink
Proper check for git repository
Browse files Browse the repository at this point in the history
  • Loading branch information
dkashyn-sfdc committed Aug 8, 2023
1 parent b322d9e commit 9339783
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,11 @@ private static String getGitUpstreamContent(WorkspaceRoot workspaceRoot, Workspa
}

private static boolean isGitRepository(WorkspaceRoot workspaceRoot) {
// TODO: What if the git repo root is a parent directory of the workspace root?
// Just call 'git rev-parse --is-inside-work-tree' or similar instead?
File gitDir = new File(workspaceRoot.directory(), ".git");
return FileOperationProvider.getInstance().isDirectory(gitDir);
ByteArrayOutputStream stdout = new ByteArrayOutputStream();

String[] args = new String[] {"git", "rev-parse", "--is-inside-work-tree"};
int retVal = ExternalTask.builder(workspaceRoot).args(args).stdout(stdout).build().run();
return retVal == 0 && "true".equals(StringUtil.trimEnd(stdout.toString(), "\n"));
}

/**
Expand Down

0 comments on commit 9339783

Please sign in to comment.