FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

expose diff flags option for repo methods · buzzkillhardball/nodegit@542270c · GitHub

Repository navigation

Commit 542270c

Browse files
committed
expose diff flags option for repo methods
1 parent 6951946 commit 542270c

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

‎lib/repository.js‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,22 +1240,27 @@ Repository.prototype.mergeheadForeach = function(callback) {
12401240
* @param {Boolean} stageNew Set to stage new filemode. Unset to unstage.
12411241
* @return {Number} 0 or an error code
12421242
*/
1243-
Repository.prototype.stageFilemode = function(filePath, stageNew) {
1243+
Repository.prototype.stageFilemode =
1244+
function(filePath, stageNew, additionalDiffOptions) {
12441245
var repo = this;
12451246
var index;
1247+
var diffOptions = additionalDiffOptions ? {
1248+
flags: additionalDiffOptions
1249+
} : undefined;
12461250
var diffPromise = stageNew ?
12471251
NodeGit.Diff.indexToWorkdir(repo, index, {
12481252
flags:
12491253
NodeGit.Diff.OPTION.SHOW_UNTRACKED_CONTENT |
1250-
NodeGit.Diff.OPTION.RECURSE_UNTRACKED_DIRS
1254+
NodeGit.Diff.OPTION.RECURSE_UNTRACKED_DIRS |
1255+
(additionalDiffOptions || 0)
12511256
})
12521257
:
12531258
repo.getHeadCommit()
12541259
.then(function getTreeFromCommit(commit) {
12551260
return commit.getTree();
12561261
})
12571262
.then(function getDiffFromTree(tree) {
1258-
return NodeGit.Diff.treeToIndex(repo, tree, index);
1263+
return NodeGit.Diff.treeToIndex(repo, tree, index, diffOptions);
12591264
});
12601265
var filePaths = (filePath instanceof Array) ? filePath : [filePath];
12611266

@@ -1311,7 +1316,11 @@ Repository.prototype.stageFilemode = function(filePath, stageNew) {
13111316
});
13121317
};
13131318

1314-
function getPathHunks(repo, index, filePath, isStaged) {
1319+
function getPathHunks(repo, index, filePath, isStaged, additionalDiffOptions) {
1320+
var diffOptions = additionalDiffOptions ? {
1321+
flags: additionalDiffOptions
1322+
} : undefined;
1323+
13151324
return Promise.resolve()
13161325
.then(function() {
13171326
if (isStaged) {
@@ -1320,14 +1329,15 @@ function getPathHunks(repo, index, filePath, isStaged) {
13201329
return commit.getTree();
13211330
})
13221331
.then(function getDiffFromTree(tree) {
1323-
return NodeGit.Diff.treeToIndex(repo, tree, index);
1332+
return NodeGit.Diff.treeToIndex(repo, tree, index, diffOptions);
13241333
});
13251334
}
13261335

13271336
return NodeGit.Diff.indexToWorkdir(repo, index, {
13281337
flags:
13291338
NodeGit.Diff.OPTION.SHOW_UNTRACKED_CONTENT |
1330-
NodeGit.Diff.OPTION.RECURSE_UNTRACKED_DIRS
1339+
NodeGit.Diff.OPTION.RECURSE_UNTRACKED_DIRS |
1340+
(additionalDiffOptions || 0)
13311341
});
13321342
})
13331343
.then(function(diff) {
@@ -1465,7 +1475,7 @@ function applySelectedLinesToTarget
14651475
* @return {Number} 0 or an error code
14661476
*/
14671477
Repository.prototype.stageLines =
1468-
function(filePath, selectedLines, isSelectionStaged) {
1478+
function(filePath, selectedLines, isSelectionStaged, additionalDiffOptions) {
14691479

14701480
var repo = this;
14711481
var index;
@@ -1479,7 +1489,8 @@ Repository.prototype.stageLines =
14791489
return NodeGit.Diff.indexToWorkdir(repo, index, {
14801490
flags:
14811491
NodeGit.Diff.OPTION.SHOW_UNTRACKED_CONTENT |
1482-
NodeGit.Diff.OPTION.RECURSE_UNTRACKED_DIRS
1492+
NodeGit.Diff.OPTION.RECURSE_UNTRACKED_DIRS |
1493+
(additionalDiffOptions || 0)
14831494
})
14841495
.then(function(diff) {
14851496
return diff.patches();
@@ -1516,7 +1527,13 @@ Repository.prototype.stageLines =
15161527
.then(function(blob) {
15171528
originalBlob = blob;
15181529

1519-
return getPathHunks(repo, index, filePath, isSelectionStaged);
1530+
return getPathHunks(
1531+
repo,
1532+
index,
1533+
filePath,
1534+
isSelectionStaged,
1535+
additionalDiffOptions
1536+
);
15201537
})
15211538
.then(function(hunks) {
15221539
return applySelectedLinesToTarget(
@@ -1559,7 +1576,8 @@ Repository.prototype.stageLines =
15591576
* selected for discarding
15601577
* @return {Number} 0 or an error code
15611578
*/
1562-
Repository.prototype.discardLines = function(filePath, selectedLines) {
1579+
Repository.prototype.discardLines =
1580+
function(filePath, selectedLines, additionalDiffOptions) {
15631581
var repo = this;
15641582
var fullFilePath = path.join(repo.workdir(), filePath);
15651583
var index;
@@ -1574,7 +1592,7 @@ Repository.prototype.discardLines = function(filePath, selectedLines) {
15741592
.then(function(content) {
15751593
originalContent = content;
15761594

1577-
return getPathHunks(repo, index, filePath, false);
1595+
return getPathHunks(repo, index, filePath, false, additionalDiffOptions);
15781596
})
15791597
.then(function(hunks) {
15801598
return applySelectedLinesToTarget(

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL