@@ -21,58 +21,53 @@ export async function init(action: ActionInterface): Promise<void | Error> {
21
21
info ( `Deploying using ${ action . tokenType } … 🔑` )
22
22
info ( 'Configuring git…' )
23
23
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 ++
24
+ async function configureGit ( throwOnError : boolean ) {
25
+ try {
26
+ await execute (
27
+ `git config --global --add safe.directory "${ action . workspace } "` ,
28
+ action . workspace ,
29
+ action . silent
30
+ )
32
31
33
- if ( attempt > ATTEMPT_LIMIT ) {
34
- throw new Error ( ) ;
35
- }
32
+ await execute (
33
+ `git config user.name "${ action . name } "` ,
34
+ action . workspace ,
35
+ action . silent
36
+ )
36
37
37
- if ( attempt > 1 ) {
38
38
await execute (
39
- `git init ` ,
39
+ `git config user.email " ${ action . email } " ` ,
40
40
action . workspace ,
41
41
action . silent
42
42
)
43
43
44
44
await execute (
45
- `git commit -m "Initial commit" --allow-empty ` ,
45
+ `git config core.ignorecase false ` ,
46
46
action . workspace ,
47
47
action . silent
48
48
)
49
+ } catch {
50
+ if ( throwOnError ) {
51
+ throw new Error ( )
52
+ }
49
53
}
54
+ }
50
55
51
- await execute (
52
- `git config --global --add safe.directory " ${ action . workspace } "` ,
53
- action . workspace ,
54
- action . silent
55
- )
56
+ try {
57
+ await configureGit ( false )
58
+ } catch {
59
+ // Attempt to re-run if initial configuration failed using git init.
60
+ await execute ( `git init` , action . workspace , action . silent )
56
61
57
62
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 } "` ,
63
+ `git commit -m "Initial commit" --allow-empty` ,
65
64
action . workspace ,
66
65
action . silent
67
66
)
68
-
69
- await execute (
70
- `git config core.ignorecase false` ,
71
- action . workspace ,
72
- action . silent
73
- )
74
- } while ( rejected )
75
-
67
+
68
+ await configureGit ( true )
69
+ }
70
+
76
71
try {
77
72
if ( ( process . env . CI && ! action . sshKey ) || action . isTest ) {
78
73
/* Ensures that previously set Git configs do not interfere with the deployment.
0 commit comments