-
Notifications
You must be signed in to change notification settings - Fork 691
[package-deps-hash] Fix build cache failures in git linked worktrees caused by GIT_DIR set by pre-commit hooks #5815
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,11 @@ | ||||||
| { | ||||||
| "changes": [ | ||||||
| { | ||||||
| "comment": "Fix build cache failures when running inside a git linked worktree via a pre-commit hook, caused by GIT_DIR being set to the per-worktree metadata directory", | ||||||
| "type": "patch", | ||||||
| "packageName": "@rushstack/package-deps-hash" | ||||||
| } | ||||||
| ], | ||||||
| "packageName": "@rushstack/package-deps-hash", | ||||||
| "email": "kfleischman@squarespace.com" | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -33,9 +33,28 @@ const STANDARD_GIT_OPTIONS: readonly string[] = [ | |||||||||
| // `git hash-object` aborts the process. Such files are typically untracked artifacts left behind | ||||||||||
| // by tooling (e.g. stray `nul` from a shell redirect). | ||||||||||
| const WINDOWS_RESERVED_BASENAMES: ReadonlySet<string> = new Set([ | ||||||||||
| 'CON', 'PRN', 'AUX', 'NUL', | ||||||||||
| 'COM1', 'COM2', 'COM3', 'COM4', 'COM5', 'COM6', 'COM7', 'COM8', 'COM9', | ||||||||||
| 'LPT1', 'LPT2', 'LPT3', 'LPT4', 'LPT5', 'LPT6', 'LPT7', 'LPT8', 'LPT9' | ||||||||||
| 'CON', | ||||||||||
| 'PRN', | ||||||||||
| 'AUX', | ||||||||||
| 'NUL', | ||||||||||
| 'COM1', | ||||||||||
| 'COM2', | ||||||||||
| 'COM3', | ||||||||||
| 'COM4', | ||||||||||
| 'COM5', | ||||||||||
| 'COM6', | ||||||||||
| 'COM7', | ||||||||||
| 'COM8', | ||||||||||
| 'COM9', | ||||||||||
| 'LPT1', | ||||||||||
| 'LPT2', | ||||||||||
| 'LPT3', | ||||||||||
| 'LPT4', | ||||||||||
| 'LPT5', | ||||||||||
| 'LPT6', | ||||||||||
| 'LPT7', | ||||||||||
| 'LPT8', | ||||||||||
| 'LPT9' | ||||||||||
|
Comment on lines
+36
to
+57
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change came from the pre-commit prettier script - not sure if my dev environment isn't set up correctly, but I can revert this specific change if needed.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine. Don't worry about it. |
||||||||||
| ]); | ||||||||||
|
|
||||||||||
| /** | ||||||||||
|
|
@@ -254,6 +273,14 @@ export function parseGitStatus(output: string): Map<string, boolean> { | |||||||||
|
|
||||||||||
| const repoRootCache: Map<string, string> = new Map(); | ||||||||||
|
|
||||||||||
| // Strip GIT_DIR/GIT_WORK_TREE: git hooks in linked worktrees set GIT_DIR to the per-worktree metadata dir, causing rev-parse --show-toplevel to return CWD instead of the worktree root. | ||||||||||
| function getCleanGitEnvironment(): NodeJS.ProcessEnv { | ||||||||||
| const env: NodeJS.ProcessEnv = { ...process.env }; | ||||||||||
| delete env.GIT_DIR; | ||||||||||
| delete env.GIT_WORK_TREE; | ||||||||||
| return env; | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| } | ||||||||||
|
|
||||||||||
| /** | ||||||||||
| * Finds the root of the current Git repository | ||||||||||
| * | ||||||||||
|
|
@@ -270,7 +297,8 @@ export function getRepoRoot(currentWorkingDirectory: string, gitPath?: string): | |||||||||
| gitPath || 'git', | ||||||||||
| ['--no-optional-locks', 'rev-parse', '--show-toplevel'], | ||||||||||
| { | ||||||||||
| currentWorkingDirectory | ||||||||||
| currentWorkingDirectory, | ||||||||||
| environment: getCleanGitEnvironment() | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we strip those env vars iff they point to nonexistent locations/locations without a Also note that AFAIK |
||||||||||
| } | ||||||||||
| ); | ||||||||||
|
|
||||||||||
|
|
@@ -305,7 +333,8 @@ async function spawnGitAsync( | |||||||||
| ): Promise<string> { | ||||||||||
| const spawnOptions: IExecutableSpawnOptions = { | ||||||||||
| currentWorkingDirectory, | ||||||||||
| stdio: ['pipe', 'pipe', 'pipe'] | ||||||||||
| stdio: ['pipe', 'pipe', 'pipe'], | ||||||||||
| environment: getCleanGitEnvironment() | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| let stdout: string = ''; | ||||||||||
|
|
@@ -591,7 +620,8 @@ export function getRepoChanges( | |||||||||
| '--' | ||||||||||
| ]), | ||||||||||
| { | ||||||||||
| currentWorkingDirectory: rootDirectory | ||||||||||
| currentWorkingDirectory: rootDirectory, | ||||||||||
| environment: getCleanGitEnvironment() | ||||||||||
| } | ||||||||||
| ); | ||||||||||
|
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generate another changelog (with type
"none") for@microsoft/rushso we can do a Rush publish with this change.