8000 Update git.ts · ushmm/github-pages-deploy-action@bb85966 · GitHub
[go: up one dir, main page]

Skip to content

Commit bb85966

Browse files
committed
Update git.ts
1 parent 338ece1 commit bb85966

File tree

1 file changed

+46
-22
lines changed

1 file changed

+46
-22
lines changed

src/git.ts

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

24-
try {
24+
// Keep trying to configure Git with various different methods until it works with a maximum of 2 attempts.
25+
const ATTEMPT_LIMIT = 2
26+
27+
let attempt = 0
28+
let rejected = false
29+
30+
do {
31+
attempt++
32+
33+
if (attempt > ATTEMPT_LIMIT) {
34+
throw new Error();
35+
}
36+
37+
if (attempt > 1) {
38+
await execute(
39+
`git init`,
40+
action.workspace,
41+
action.silent
42+
)
43+
44+
await execute(
45+
`git commit -m "Initial commit" --allow-empty`,
46+
action.workspace,
47+
action.silent
48+
)
49+
}
50+
2551
await execute(
2652
`git config --global --add safe.directory "${action.workspace}"`,
2753
action.workspace,
2854
action.silent
2955
)
30-
} catch {
31-
info('Unable to set workspace as a safe directory…')
32-
}
33-
34-
await execute(
35-
`git config user.name "${action.name}"`,
36-
action.workspace,
37-
action.silent
38-
)
39-
40-
await execute(
41-
`git config user.email "${action.email}"`,
42-
action.workspace,
43-
action.silent
44-
)
45-
46-
await execute(
47-
`git config core.ignorecase false`,
48-
action.workspace,
49-
action.silent
50-
)
5156

57+
await execute(
58+
`git config user.name "${action.name}"`,
59+
action.workspace,
60+
action.silent
61+
)
62+
63+
await execute(
64+
`git config user.email "${action.email}"`,
65+
action.workspace,
66+
action.silent
67+
)
68+
69+
await execute(
70+
`git config core.ignorecase false`,
71+
action.workspace,
72+
action.silent
73+
)
74+
} while(rejected)
75+
5276
try {
5377
if ((process.env.CI && !action.sshKey) || action.isTest) {
5478
/* Ensures that previously set Git configs do not interfere with the deployment.

0 commit comments

Comments
 (0)
0