Skip to content

Commit afde735

Browse files
committed
fix: return the actual rev we cloned for all cloning strategies
1 parent 6dc0aef commit afde735

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

lib/clone.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,18 @@ const defaultTarget = (repo, /* istanbul ignore next */ cwd = process.cwd()) =>
5050
path.resolve(cwd, path.basename(repo.replace(/[/\\]?\.git$/, '')))
5151

5252
const clone = (repo, revs, ref, revDoc, target, opts) => {
53+
const git = (args) => spawn(args, { ...opts, cwd: target })
54+
return cloneStrategy(repo, revs, ref, revDoc, target, opts)
55+
.then(() => git(['rev-parse', '--revs-only', 'HEAD']))
56+
.then(({ stdout }) => stdout.trim())
57+
}
58+
59+
const cloneStrategy = (repo, revs, ref, revDoc, target, opts) => {
5360
if (!revDoc) {
5461
return unresolved(repo, ref, target, opts)
5562
}
5663
if (revDoc.sha === revs.refs.HEAD.sha) {
57-
return plain(repo, revDoc, target, opts)
64+
return plain(repo, target, opts)
5865
}
5966
if (revDoc.type === 'tag' || revDoc.type === 'branch') {
6067
return branch(repo, revDoc, target, opts)
@@ -101,7 +108,6 @@ const other = (repo, revDoc, target, opts) => {
101108
.then(() => git(fetchOrigin))
102109
.then(() => git(['checkout', revDoc.sha]))
103110
.then(() => updateSubmodules(target, opts))
104-
.then(() => revDoc.sha)
105111
}
106112

107113
// tag or branches. use -b
@@ -120,11 +126,11 @@ const branch = (repo, revDoc, target, opts) => {
120126
if (isWindows(opts)) {
121127
args.push('--config', 'core.longpaths=true')
122128
}
123-
return spawn(args, opts).then(() => revDoc.sha)
129+
return spawn(args, opts)
124130
}
125131

126132
// just the head. clone it
127-
const plain = (repo, revDoc, target, opts) => {
133+
const plain = (repo, target, opts) => {
128134
const args = [
129135
'clone',
130136
repo,
@@ -137,7 +143,7 @@ const plain = (repo, revDoc, target, opts) => {
137143
if (isWindows(opts)) {
138144
args.push('--config', 'core.longpaths=true')
139145
}
140-
return spawn(args, opts).then(() => revDoc.sha)
146+
return spawn(args, opts)
141147
}
142148

143149
const updateSubmodules = async (target, opts) => {
@@ -167,6 +173,4 @@ const unresolved = (repo, ref, target, opts) => {
167173
.then(() => git(['init']))
168174
.then(() => git(['checkout', ref]))
169175
.then(() => updateSubmodules(target, opts))
170-
.then(() => git(['rev-parse', '--revs-only', 'HEAD']))
171-
.then(({ stdout }) => stdout.trim())
172176
}

0 commit comments

Comments
 (0)