@@ -37,16 +37,23 @@ async function main() {
37
37
title : core . getInput ( "title" ) ,
38
38
body : core . getInput ( "body" ) ,
39
39
branch : core . getInput ( "branch" ) ,
40
+ path : core . getInput ( "path" ) ,
40
41
commitMessage : core . getInput ( "commit-message" ) ,
41
42
author : core . getInput ( "author" )
42
43
} ;
43
44
44
45
core . debug ( `Inputs: ${ inspect ( inputs ) } ` ) ;
45
46
46
- const { hasChanges, hasUncommitedChanges } = await getLocalChanges ( ) ;
47
+ const { hasChanges, hasUncommitedChanges } = await getLocalChanges (
48
+ inputs . path
49
+ ) ;
47
50
48
51
if ( ! hasChanges ) {
49
- core . info ( "No local changes" ) ;
52
+ if ( inputs . path ) {
53
+ core . info ( `No local changes matchin "${ inputs . path } "` ) ;
54
+ } else {
55
+ core . info ( "No local changes" ) ;
56
+ }
50
57
process . exit ( 0 ) ; // there is currently no neutral exit code
51
58
}
52
59
@@ -70,10 +77,16 @@ async function main() {
70
77
} ) ;
71
78
}
72
79
73
- core . debug ( `Comitting local changes` ) ;
74
- await command ( "git add ." , { shell : true } ) ;
80
+ if ( inputs . path ) {
81
+ core . debug ( `Committing local changes matching "${ inputs . path } "` ) ;
82
+ await command ( `git add "${ inputs . path } "` , { shell : true } ) ;
83
+ } else {
84
+ core . debug ( `Committing all local changes` ) ;
85
+ await command ( "git add ." , { shell : true } ) ;
86
+ }
87
+
75
88
await command (
76
- `git commit -a - m "${ inputs . commitMessage } " --author "${ inputs . author } "` ,
89
+ `git commit -m "${ inputs . commitMessage } " --author "${ inputs . author } "` ,
77
90
{ shell : true }
78
91
) ;
79
92
} else {
@@ -84,12 +97,11 @@ async function main() {
84
97
const remoteBranchExists = await checkOutRemoteBranch ( inputs . branch ) ;
85
98
86
99
core . debug ( `Pushing local changes` ) ;
87
- const { stdout : pushStdOut , stderr : pushStdErr } = await command (
100
+ await command (
88
101
`git push -f https://x-access-token:${ process . env . GITHUB_TOKEN } @github.com/${ process . env . GITHUB_REPOSITORY } .git HEAD:refs/heads/${ inputs . branch } ` ,
89
102
{ shell : true }
90
103
) ;
91
104
92
- // no idea why the `git push` output goes into stderr. Checking in both just in case.
93
105
if ( remoteBranchExists ) {
94
106
core . info ( `Existing pull request for "${ inputs . branch } " updated` ) ;
95
107
return ;
@@ -115,8 +127,10 @@ async function main() {
115
127
}
116
128
}
117
129
118
- async function getLocalChanges ( ) {
119
- const { stdout } = await command ( "git status" , { shell : true } ) ;
130
+ async function getLocalChanges ( path ) {
131
+ const { stdout } = await command ( `git status ${ path || "*" } ` , {
132
+ shell : true
133
+ } ) ;
120
134
121
135
if ( / Y o u r b r a n c h i s u p t o d a t e / . test ( stdout ) ) {
122
136
return ;
@@ -162,16 +176,27 @@ async function setGitUser({ name, email }) {
162
176
163
177
async function checkOutRemoteBranch ( branch ) {
164
178
try {
179
+ const { stdout } = await command ( `git rev-parse --abbrev-ref HEAD` , {
180
+ shell : true
181
+ } ) ;
182
+
183
+ if ( stdout === branch ) {
184
+ core . info ( `Already in "${ branch } ".` ) ;
185
+ return true ;
186
+ }
187
+
165
188
await command (
166
189
`git fetch https://x-access-token:${ process . env . GITHUB_TOKEN } @github.com/${ process . env . GITHUB_REPOSITORY } .git ${ branch } :${ branch } ` ,
167
190
{ shell : true }
168
191
) ;
192
+
169
193
await command ( `git checkout ${ branch } ` , { shell : true } ) ;
170
194
core . info ( `Remote branch "${ branch } " checked out locally.` ) ;
171
- await command ( `git rebase -Xtheirs -` , { shell : true } ) ;
195
+ await command ( `git rebase -Xtheirs --autostash - ` , { shell : true } ) ;
172
196
return true ;
173
197
} catch ( error ) {
174
198
core . info ( `Branch "${ branch } " does not yet exist on remote.` ) ;
199
+ await command ( `git checkout -b ${ branch } ` , { shell : true } ) ;
175
200
return false ;
176
201
}
177
202
}
0 commit comments