Skip to content

Commit

Permalink
refactor isUpdated
Browse files Browse the repository at this point in the history
  • Loading branch information
didil committed Feb 17, 2017
1 parent 665b9cf commit 5f9b2fc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
28 changes: 13 additions & 15 deletions lib/git/git.js
Expand Up @@ -189,27 +189,25 @@ git.isUpdated = function (folder, cb) {
return cb(err);
}

var prefix = '';

if (data.branch_exists_on_remote)
prefix = data.remote + '/';

exec("cd '" + folder + "';LC_ALL=en_US.UTF-8 git remote update >> /dev/null 2>&1; git log " + prefix + data.branch +
" --pretty=oneline -n 1", {timeout: 60000, maxBuffer: MAXBUFFER},
exec("cd '" + folder + "';LC_ALL=en_US.UTF-8 git remote update", {timeout: 60000, maxBuffer: MAXBUFFER},
function (err, stdout, stderr) {
if (err) {
return cb(err);
}

var res = {};
var remote = data.branch_exists_on_remote ? data.remote : null;
jsGitService.getLastCommit(folder, data.branch, remote, function (err, commit) {
if (err) {
return cb(err);
}

if (stdout.substring(0, 40) === data.revision.substring(0, 40))
res.is_up_to_date = true;
else
res.is_up_to_date = false;
res.new_revision = stdout.substring(0, 40);
res.current_revision = data.revision.substring(0, 40);
return cb(null, res);
var res = {
new_revision: commit.hash,
current_revision: data.revision,
is_up_to_date: (commit.hash === data.revision)
};
return cb(null, res);
});
});
});
};
Expand Down
13 changes: 13 additions & 0 deletions lib/git/js-git-service.js
Expand Up @@ -29,6 +29,19 @@ jsGitService.getHeadCommit = function (folder, remote, cb) {
jsGitService.getLastCommitByRef(repo, ref, cb);
};

jsGitService.getLastCommit = function (folder, branch, remote, cb) {
if (cb === undefined) {
cb = remote;
remote = null;
}

var repo = jsGitService.loadRepo(folder);

var ref = remote ? `refs/remotes/origin/${branch}` : `refs/heads/${branch}`;

jsGitService.getLastCommitByRef(repo, ref, cb);
};

jsGitService.getLastCommitByRef = function (repo, ref, cb) {
repo.readRef(ref, function (err, commitHash) {
if (err) {
Expand Down

0 comments on commit 5f9b2fc

Please sign in to comment.