Skip to content

Commit 0f92767

Browse files
Merge pull request #228 from technote-space/release/v1.0.5
Release/v1.0.5
2 parents b96110a + 822d6a2 commit 0f92767

File tree

4 files changed

+24
-20
lines changed

4 files changed

+24
-20
lines changed

__tests__/git-helper.test.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ describe('GitHelper', () => {
110110
await helper.checkout(workDir, context());
111111

112112
execCalledWith(mockExec, [
113-
'rm -rdf \'.work\'',
114-
'git init \'.\'',
115113
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
116114
'git fetch --no-tags origin \'refs/heads/test-ref:refs/remotes/origin/test-ref\' || :',
117115
'git checkout -qf test-sha',
@@ -124,8 +122,6 @@ describe('GitHelper', () => {
124122
await helper.checkout(workDir, context({ref: 'refs/pull/123/merge'}));
125123

126124
execCalledWith(mockExec, [
127-
'rm -rdf \'.work\'',
128-
'git init \'.\'',
129125
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
130126
'git fetch --no-tags origin \'refs/pull/123/merge:refs/pull/123/merge\' || :',
131127
'git checkout -qf test-sha',
@@ -138,8 +134,6 @@ describe('GitHelper', () => {
138134
await helper.checkout(workDir, context({ref: 'refs/tags/v1.2.3'}));
139135

140136
execCalledWith(mockExec, [
141-
'rm -rdf \'.work\'',
142-
'git init \'.\'',
143137
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
144138
'git fetch --no-tags origin \'refs/tags/v1.2.3:refs/tags/v1.2.3\' || :',
145139
'git checkout -qf test-sha',
@@ -179,6 +173,17 @@ describe('GitHelper', () => {
179173

180174
await helper.addOrigin(workDir, context());
181175

176+
execCalledWith(mockExec, [
177+
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
178+
]);
179+
});
180+
181+
it('should run git init and git remote add', async() => {
182+
const mockExec = spyOnExec();
183+
setExists([false, true]);
184+
185+
await helper.addOrigin(workDir, context());
186+
182187
execCalledWith(mockExec, [
183188
`rm -rdf '${workDir}'`,
184189
'git init \'.\'',
@@ -194,8 +199,6 @@ describe('GitHelper', () => {
194199
await helper.fetchOrigin(workDir, context());
195200

196201
execCalledWith(mockExec, [
197-
`rm -rdf '${workDir}'`,
198-
'git init \'.\'',
199202
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
200203
'git fetch origin || :',
201204
]);
@@ -207,8 +210,6 @@ describe('GitHelper', () => {
207210
await helper.fetchOrigin(workDir, context(), ['--no-tags']);
208211

209212
execCalledWith(mockExec, [
210-
`rm -rdf '${workDir}'`,
211-
'git init \'.\'',
212213
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
213214
'git fetch --no-tags origin || :',
214215
]);
@@ -220,8 +221,6 @@ describe('GitHelper', () => {
220221
await helper.fetchOrigin(workDir, context(), undefined, ['+refs/pull/*/merge:refs/remotes/pull/*/merge', '+refs/heads/hoge:refs/remotes/origin/hoge']);
221222

222223
execCalledWith(mockExec, [
223-
`rm -rdf '${workDir}'`,
224-
'git init \'.\'',
225224
'git remote add origin \'https://octocat:[email protected]/hello/world.git\' > /dev/null 2>&1 || :',
226225
'git fetch origin \'+refs/pull/*/merge:refs/remotes/pull/*/merge\' \'+refs/heads/hoge:refs/remotes/origin/hoge\' || :',
227226
]);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@technote-space/github-action-helper",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Helper to filter GitHub Action.",
55
"author": {
66
"name": "Technote",
@@ -40,7 +40,7 @@
4040
"eslint": "^6.8.0",
4141
"jest": "^25.1.0",
4242
"jest-circus": "^25.1.0",
43-
"nock": "^11.7.2",
43+
"nock": "^11.8.2",
4444
"ts-jest": "^25.2.0",
4545
"typescript": "^3.7.5"
4646
},

src/git-helper.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,14 @@ export default class GitHelper {
8484

8585
/**
8686
* @param {string} workDir work dir
87+
* @param {boolean} refresh refresh?
8788
* @return {Promise<void>} void
8889
*/
89-
private initialize = async(workDir: string): Promise<void> => {
90+
private initialize = async(workDir: string, refresh = true): Promise<void> => {
91+
if (isCloned(workDir) && !refresh) {
92+
return;
93+
}
94+
9095
if (fs.existsSync(workDir)) {
9196
await this.runCommand(workDir, {command: 'rm', args: ['-rdf', workDir]});
9297
}
@@ -106,7 +111,7 @@ export default class GitHelper {
106111
* @return {Promise<void>} void
107112
*/
108113
public addOrigin = async(workDir: string, context: Context): Promise<void> => {
109-
await this.initialize(workDir);
114+
await this.initialize(workDir, false);
110115
await this.runCommand(workDir, {
111116
command: 'git remote add',
112117
args: ['origin', getGitUrlWithToken(context, this.token)],

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2833,10 +2833,10 @@ nice-try@^1.0.4:
28332833
resolved "https://registry.yarnpkg.com/nice-try/-/nice-try-1.0.5.tgz#a3378a7696ce7d223e88fc9b764bd7ef1089e366"
28342834
integrity sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==
28352835

2836-
nock@^11.7.2:
2837-
version "11.7.2"
2838-
resolved "https://registry.yarnpkg.com/nock/-/nock-11.7.2.tgz#4cee4fa838dc3635c074c5b3436bcdec7f7ee213"
2839-
integrity sha512-7swr5bL1xBZ5FctyubjxEVySXOSebyqcL7Vy1bx1nS9IUqQWj81cmKjVKJLr8fHhtzI1MV8nyCdENA/cGcY1+Q==
2836+
nock@^11.8.2:
2837+
version "11.8.2"
2838+
resolved "https://registry.yarnpkg.com/nock/-/nock-11.8.2.tgz#7845608d57769f41375b63521a7e6b554f4cdbb2"
2839+
integrity sha512-udrFXJ/aqPM9NmrKOcNJ67lvrs/zroNq2sbumhaMPW5JLNy/6LsWiZEwU9DiQIUHOcOCR4MPeqIG7uQNbDGExA==
28402840
dependencies:
28412841
debug "^4.1.0"
28422842
json-stringify-safe "^5.0.1"

0 commit comments

Comments
 (0)