Read-only mirror — the public repositories of the Forgejo instance, refreshed every 10 minutes. The live instance (fg.dieschoenewolke.de) is reachable only over the VPN; clone here with https://git.dieschoenewolke.de/git/<owner>/<repo>.git.
summaryrefslogtreecommitdiff
path: root/src/git-source-provider.ts
diff options
context:
space:
mode:
authorTingluo Huang <tingluohuang@github.com>2022-04-21 10:12:11 -0400
committerGitHub <noreply@github.com>2022-04-21 10:12:11 -0400
commit013b3856ba9ad25709645c555998be6313f542b3 (patch)
tree58f72d63e8dbe42f00aae96a6ba3140c11a41a81 /src/git-source-provider.ts
parent47d502ed80d427575b8b4f55f7aaeb7572cfe5db (diff)
Add set-safe-directory input to allow customers to take control. (#770) (#776)
* Add set-safe-directory input to allow customers to take control.
Diffstat (limited to 'src/git-source-provider.ts')
-rw-r--r--src/git-source-provider.ts35
1 files changed, 33 insertions, 2 deletions
diff --git a/src/git-source-provider.ts b/src/git-source-provider.ts
index 0913229..545a7a3 100644
--- a/src/git-source-provider.ts
+++ b/src/git-source-provider.ts
@@ -40,7 +40,24 @@ export async function getSource(settings: IGitSourceSettings): Promise<void> {
try {
if (git) {
authHelper = gitAuthHelper.createAuthHelper(git, settings)
- await authHelper.configureTempGlobalConfig()
+ if (settings.setSafeDirectory) {
+ // Setup the repository path as a safe directory, so if we pass this into a container job with a different user it doesn't fail
+ // Otherwise all git commands we run in a container fail
+ await authHelper.configureTempGlobalConfig()
+ core.info(
+ `Adding repository directory to the temporary git global config as a safe directory`
+ )
+
+ await git
+ .config('safe.directory', settings.repositoryPath, true, true)
+ .catch(error => {
+ core.info(
+ `Failed to initialize safe directory with error: ${error}`
+ )
+ })
+
+ stateHelper.setSafeDirectory()
+ }
}
// Prepare existing directory, otherwise recreate
@@ -249,7 +266,21 @@ export async function cleanup(repositoryPath: string): Promise<void> {
// Remove auth
const authHelper = gitAuthHelper.createAuthHelper(git)
try {
- await authHelper.configureTempGlobalConfig(repositoryPath)
+ if (stateHelper.PostSetSafeDirectory) {
+ // Setup the repository path as a safe directory, so if we pass this into a container job with a different user it doesn't fail
+ // Otherwise all git commands we run in a container fail
+ await authHelper.configureTempGlobalConfig()
+ core.info(
+ `Adding repository directory to the temporary git global config as a safe directory`
+ )
+
+ await git
+ .config('safe.directory', repositoryPath, true, true)
+ .catch(error => {
+ core.info(`Failed to initialize safe directory with error: ${error}`)
+ })
+ }
+
await authHelper.removeAuth()
} finally {
await authHelper.removeGlobalConfig()