-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into script-injection-updates
- Loading branch information
Showing
39 changed files
with
835 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,34 @@ | ||
import { execPromiseStdout } from './child-process' | ||
|
||
export const gitBranchName = async () => await execPromiseStdout('git rev-parse --abbrev-ref HEAD') | ||
.catch(() => undefined) | ||
export function gitContext(cwd: string = process.cwd()) { | ||
const execGit = async (command: string) => await execPromiseStdout(`git ${command}`, { cwd }) | ||
const branchName = async () => await execGit('rev-parse --abbrev-ref HEAD') | ||
.catch(() => undefined) | ||
|
||
export const gitCommit = async () => await execPromiseStdout('git rev-parse HEAD') | ||
.catch(() => undefined) | ||
const head = async () => await execGit('rev-parse HEAD') | ||
.catch(() => undefined) | ||
|
||
export const gitAuthor = async (commit?: string) => { | ||
const [email, name] = await Promise.all([ | ||
`git log -1 ${commit} --pretty=format:'%ae'`, | ||
`git log -1 ${commit} --pretty=format:'%an'`, | ||
].map(cmd => execPromiseStdout(cmd).catch(() => undefined))) | ||
return email === undefined || name === undefined ? undefined : { name, email } | ||
} | ||
const author = async (commit?: string) => { | ||
const [email, name] = await Promise.all([ | ||
`log -1 ${commit} --pretty=format:'%ae'`, | ||
`log -1 ${commit} --pretty=format:'%an'`, | ||
].map(cmd => execGit(cmd).catch(() => undefined))) | ||
return email === undefined || name === undefined ? undefined : { name, email } | ||
} | ||
|
||
const remoteTrackingBranchUrl = async (localBranch?: string) => { | ||
const b = localBranch ?? (await execGit('rev-parse --abbrev-ref HEAD')) | ||
const trackingRemote = await execGit(`config branch.${b}.remote || true`) | ||
if (!trackingRemote) { | ||
return undefined | ||
} | ||
return await execGit(`config remote.${trackingRemote}.url`) | ||
} | ||
|
||
export const gitRemoteTrackingBranchUrl = async (localBranch?: string) => { | ||
const b = localBranch ?? (await execPromiseStdout('git rev-parse --abbrev-ref HEAD')) | ||
const trackingRemote = await execPromiseStdout(`git config branch.${b}.remote || true`) | ||
if (!trackingRemote) { | ||
return undefined | ||
return { | ||
branchName, | ||
commit: head, | ||
author, | ||
remoteTrackingBranchUrl, | ||
} | ||
return await execPromiseStdout(`git config remote.${trackingRemote}.url`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.