Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RepoRoot Logic #126

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions change/change-ffd4f222-e98f-4b58-af0f-ae2d88f70301.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"type": "patch",
"comment": "Indicate better that it is not the cause of failure when git cannot be found on the path, and allow host to set repo root path",
"packageName": "@boll/core",
"email": "[email protected]",
"dependentChangeType": "patch"
}
]
}
15 changes: 13 additions & 2 deletions packages/core/src/git-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ const defaultIgnoreFileName = ".gitignore";
let repoRoot: string | undefined = undefined;
let ignoreFiles: { [cwd: string]: { [ignoreFileName: string]: string[] } } = {};

/**
* Some build environments don't have git on the path during build phase.
* Yet we want to lint during the build to not lave any pref on the table.
* This allows these repo'sto short-circuit the call to git and determine
* the repo root to avoid the message.
*/
export function setRepoRoot(root: string): void {
repoRoot = root;
}

export function getRepoRoot(): string {
if (repoRoot) {
return repoRoot;
Expand All @@ -15,8 +25,9 @@ export function getRepoRoot(): string {
repoRoot = resolve(execSync("git rev-parse --show-toplevel").toString().trim());
return repoRoot;
} catch (e) {
console.warn(e);
return process.cwd();
repoRoot = process.cwd();
console.warn(`Warning: Failed to execute git command to determ ine repo root. Using ${repoRoot}: ${e}`);
dannyvv marked this conversation as resolved.
Show resolved Hide resolved
return repoRoot;
}
}

Expand Down
Loading