Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions lib/clone.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@ const defaultTarget = (repo, /* istanbul ignore next */ cwd = process.cwd()) =>
path.resolve(cwd, path.basename(repo.replace(/[/\\]?\.git$/, '')))

const clone = (repo, revs, ref, revDoc, target, opts) => {
const git = (args) => spawn(args, { ...opts, cwd: target })
return cloneStrategy(repo, revs, ref, revDoc, target, opts)
.then(() => git(['rev-parse', '--revs-only', 'HEAD']))
.then(({ stdout }) => stdout.trim())
}

const cloneStrategy = (repo, revs, ref, revDoc, target, opts) => {
if (!revDoc) {
return unresolved(repo, ref, target, opts)
}
if (revDoc.sha === revs.refs.HEAD.sha) {
return plain(repo, revDoc, target, opts)
return plain(repo, target, opts)
}
if (revDoc.type === 'tag' || revDoc.type === 'branch') {
return branch(repo, revDoc, target, opts)
Expand Down Expand Up @@ -101,7 +108,6 @@ const other = (repo, revDoc, target, opts) => {
.then(() => git(fetchOrigin))
.then(() => git(['checkout', revDoc.sha]))
.then(() => updateSubmodules(target, opts))
.then(() => revDoc.sha)
}

// tag or branches. use -b
Expand All @@ -120,11 +126,11 @@ const branch = (repo, revDoc, target, opts) => {
if (isWindows(opts)) {
args.push('--config', 'core.longpaths=true')
}
return spawn(args, opts).then(() => revDoc.sha)
return spawn(args, opts)
}

// just the head. clone it
const plain = (repo, revDoc, target, opts) => {
const plain = (repo, target, opts) => {
const args = [
'clone',
repo,
Expand All @@ -137,7 +143,7 @@ const plain = (repo, revDoc, target, opts) => {
if (isWindows(opts)) {
args.push('--config', 'core.longpaths=true')
}
return spawn(args, opts).then(() => revDoc.sha)
return spawn(args, opts)
}

const updateSubmodules = async (target, opts) => {
Expand Down Expand Up @@ -167,6 +173,4 @@ const unresolved = (repo, ref, target, opts) => {
.then(() => git(['init']))
.then(() => git(['checkout', ref]))
.then(() => updateSubmodules(target, opts))
.then(() => git(['rev-parse', '--revs-only', 'HEAD']))
.then(({ stdout }) => stdout.trim())
}