diff --git a/lib/repository.js b/lib/repository.js index 121543ebd..1da4e29f5 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -1361,20 +1361,22 @@ Repository.prototype.stageLines = var repo = this; var index; - var diffPromise = isSelectionStaged ? - repo.getHeadCommit() - .then(function getTreeFromCommit(commit) { - return commit.getTree(); - }) - .then(function getDiffFromTree(tree) { - return NodeGit.Diff.treeToIndex(repo, tree, index); - }) - : - NodeGit.Diff.indexToWorkdir(repo, index, { - flags: - NodeGit.Diff.OPTION.SHOW_UNTRACKED_CONTENT | - NodeGit.Diff.OPTION.RECURSE_UNTRACKED_DIRS - }); + var diffPromise = function diffPromise() { + return isSelectionStaged ? + repo.getHeadCommit() + .then(function getTreeFromCommit(commit) { + return commit.getTree(); + }) + .then(function getDiffFromTree(tree) { + return NodeGit.Diff.treeToIndex(repo, tree, index); + }) + : + NodeGit.Diff.indexToWorkdir(repo, index, { + flags: + NodeGit.Diff.OPTION.SHOW_UNTRACKED_CONTENT | + NodeGit.Diff.OPTION.RECURSE_UNTRACKED_DIRS + }); + }; //The following chain checks if there is a patch with no hunks left for the //file, and no filemode changes were done on the file. It is then safe to @@ -1409,18 +1411,13 @@ Repository.prototype.stageLines = }); }; - var indexLock = repo.path().replace(".git/", "") + ".git/index.lock"; - - return fse.remove(indexLock) - .then(function() { - return repo.openIndex(); - }) + return repo.openIndex() .then(function(indexResult) { index = indexResult; return index.read(1); }) .then(function() { - return diffPromise; + return diffPromise(); }) .then(function(diff) { if (!(NodeGit.Status.file(repo, filePath) &