Check for symlinked gitconfig

We don't want to edit the user's actual gitconfig, we only want to copy their setup.

If the file is symlinked, we resolve the link and copy the source file instead.
This commit is contained in:
Scott Driggers 2021-12-08 12:05:26 -05:00
parent 230611dbd0
commit 6bf54c5e8a
No known key found for this signature in database
GPG key ID: C5B0A5DC4CBA0AA3
2 changed files with 22 additions and 5 deletions

View file

@ -104,8 +104,16 @@ class GitAuthHelper {
}
}
if (configExists) {
core.info(`Copying '${gitConfigPath}' to '${newGitConfigPath}'`)
await io.cp(gitConfigPath, newGitConfigPath)
if ((await fs.promises.lstat(gitConfigPath)).isSymbolicLink()) {
core.info(`.gitconfig file at ${gitConfigPath} is a symlink, copying the true file instead`)
// get true link
const symlinkFull: string = await fs.promises.readlink(gitConfigPath)
core.info(`Copying '${symlinkFull}' to '${newGitConfigPath}'`)
await io.cp(symlinkFull, newGitConfigPath)
} else {
core.info(`Copying '${gitConfigPath}' to '${newGitConfigPath}'`)
await io.cp(gitConfigPath, newGitConfigPath)
}
} else {
await fs.promises.writeFile(newGitConfigPath, '')
}