Skip to content

Commit

Permalink
[fix] fetch-then-reset rather than reset-then-destructive-pull [Fixes S…
Browse files Browse the repository at this point in the history
  • Loading branch information
doublerebel committed Jan 26, 2015
1 parent b9ba001 commit 68c1e88
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ function httpCloneCmd(config, branch) {
}
}

function pull(dest, config, context, done) {
context.cmd({
cmd: 'git reset --hard',
cwd: dest
}, function (exitCode) {
utils.gitCmd('git pull', dest, config.auth, context, done)
function pull(dest, config, context, branch, done) {
utils.gitCmd('git fetch', dest, config.auth, context, function (exitCode) {
context.cmd({
cmd: 'git reset --hard origin/' + branch,
cwd: dest
}, done)
})
}

Expand Down Expand Up @@ -124,8 +124,7 @@ function fetch(dest, config, job, context, done) {
if (config.auth.type === 'ssh' && !config.auth.privkey) {
config.auth.privkey = getMasterPrivKey(job.project.branches)
}
var get = pull
, cloning = false
var cloning = false
, pleaseClone = function () {
cloning = true
fs.mkdirp(dest, function () {
Expand All @@ -140,7 +139,7 @@ function fetch(dest, config, job, context, done) {
fs.exists(path.join(dest, '.git'), function (exists) {
if (exists) {
context.comment('restored code from cache')
return pull(dest, config, context, updateCache)
return pull(dest, config, context, job.ref.branch, updateCache)
}
fs.remove(dest, function(err) {
pleaseClone()
Expand Down

0 comments on commit 68c1e88

Please sign in to comment.