Skip to content

Commit 1230c33

Browse files
authored
Safe directory fix (#1085)
* Potential fix for safe directory issue * Update git.ts * Update git.ts
1 parent 91c3cd7 commit 1230c33

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

__tests__/git.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe('git', () => {
5555
})
5656

5757
await init(action)
58-
expect(execute).toBeCalledTimes(6)
58+
expect(execute).toBeCalledTimes(7)
5959
})
6060

6161
it('should catch when a function throws an error', async () => {
@@ -102,7 +102,7 @@ describe('git', () => {
102102
})
103103

104104
await init(action)
105-
expect(execute).toBeCalledTimes(6)
105+
expect(execute).toBeCalledTimes(7)
106106
})
107107

108108
it('should not unset git config if a user is using ssh', async () => {
@@ -124,7 +124,7 @@ describe('git', () => {
124124
})
125125

126126
await init(action)
127-
expect(execute).toBeCalledTimes(5)
127+
expect(execute).toBeCalledTimes(6)
128128

129129
process.env.CI = undefined
130130
})
@@ -145,7 +145,7 @@ describe('git', () => {
145145
})
146146

147147
await init(action)
148-
expect(execute).toBeCalledTimes(6)
148+
expect(execute).toBeCalledTimes(7)
149149
})
150150
})
151151

__tests__/main.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ describe('main', () => {
5353
debug: true
5454
})
5555
await run(action)
56-
expect(execute).toBeCalledTimes(16)
56+
expect(execute).toBeCalledTimes(17)
5757
expect(rmRF).toBeCalledTimes(1)
5858
expect(exportVariable).toBeCalledTimes(1)
5959
})
@@ -73,7 +73,7 @@ describe('main', () => {
7373
isTest: TestFlag.HAS_CHANGED_FILES
7474
})
7575
await run(action)
76-
expect(execute).toBeCalledTimes(19)
76+
expect(execute).toBeCalledTimes(20)
7777
expect(rmRF).toBeCalledTimes(1)
7878
expect(exportVariable).toBeCalledTimes(1)
7979
})

src/git.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,16 @@ export async function init(action: ActionInterface): Promise<void | Error> {
2121
info(`Deploying using ${action.tokenType}… 🔑`)
2222
info('Configuring git…')
2323

24+
try {
25+
await execute(
26+
`git config --global --add safe.directory "${action.workspace}"`,
27+
action.workspace,
28+
action.silent
29+
)
30+
} catch {
31+
info('Unable to set workspace as a safe directory…')
32+
}
33+
2434
await execute(
2535
`git config user.name "${action.name}"`,
2636
action.workspace,

0 commit comments

Comments
 (0)