Skip to content
61 changes: 60 additions & 1 deletion generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@
"selfFreeing": true,
"functions": {
"git_commit_amend": {
"isAsync": true,
"args": {
"author": {
"isOptional": true
Expand Down Expand Up @@ -1268,13 +1269,35 @@
"merge": {
"functions": {
"git_merge": {
"isAsync": true,
"args": {
"repo": {
"cppClassName": "GitRepository",
"cType": "git_repository *",
"jsClassName": "Repo"
},
"their_heads": {
"cType": "const git_annotated_commit **",
"cppClassName": "Array",
"jsClassName": "Array",
"arrayElementCppClassName": "GitAnnotatedCommit"
},
"their_heads_len": {
"cType": "size_t",
"cppClassName": "Number",
"jsClassName": "Number"
},
"merge_opts": {
"cType": "git_merge_options *",
"cppClassName": "GitMergeOptions"
},
"checkout_opts": {
"cType": "git_checkout_options *",
"cppClassName": "GitCheckoutOptions"
}
},
"return": {
"isErrorCode": true
}
},
"git_merge_analysis": {
Expand Down Expand Up @@ -1659,8 +1682,12 @@
"rebase": {
"functions": {
"git_rebase_commit": {
"isAsync": true,
"args": {
"id": {
"cType": "git_oid *",
"cppClassName": "GitOid",
"jsClassName": "Oid",
"isReturn": true,
"shouldAlloc": true
},
Expand All @@ -1673,6 +1700,9 @@
"message": {
"isOptional": true
}
},
"return": {
"isErrorCode": true
}
},
"git_rebase_finish": {
Expand Down Expand Up @@ -1700,6 +1730,22 @@
"isOptional": true
}
}
},
"git_rebase_abort": {
"isAsync": true,
"args": {
"rebase": {
"cType": "git_rebase *",
"cppClassName": "GitRebase",
"jsClassName": "Rebase",
"isOptional": false,
"isSelf": true,
"isReturn": false
}
},
"return": {
"isErrorCode": true
}
}
}
},
Expand Down Expand Up @@ -1798,6 +1844,17 @@
"needsForwardDeclaration": false,
"ignore": true
},
"reflog": {
"functions": {
"git_reflog_write": {
"isAsync": true,
"isSelf": true,
"return": {
"isErrorCode": true
}
}
}
},
"reflog_entry": {
"functions": {
"git_reflog_entry_id_new": {
Expand Down Expand Up @@ -2241,9 +2298,11 @@
"isAsync": false
},
"git_status_file": {
"isAsync": true,
"args": {
"status_flags": {
"isReturn": true
"isReturn": true,
"shouldAlloc": true
},
"return": {
"isErrorCode": true
Expand Down
11 changes: 11 additions & 0 deletions lib/rebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var shallowClone = NodeGit.Utils.shallowClone;

var _init = Rebase.init;
var _open = Rebase.open;
var _abort = Rebase.prototype.abort;
var _commit = Rebase.prototype.commit;
/**
* Initializes a rebase
* @async
Expand Down Expand Up @@ -83,3 +85,12 @@ Rebase.open = function(repository, options) {
);
return _open(repository, options);
};

Rebase.prototype.commit = function(author, committer, encoding, message) {
return _commit.call(this, author, committer, encoding, message);
};

Rebase.prototype.abort = function() {
return _abort.call(this);
};

107 changes: 69 additions & 38 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ function getPathHunks(repo, index, filePath, isStaged, additionalDiffOptions) {
});
})
.then(function(diff) {
if (!(NodeGit.Status.file(repo, filePath) &
NodeGit.Status.STATUS.WT_MODIFIED) &&
!(NodeGit.Status.file(repo, filePath) &
NodeGit.Status.STATUS.INDEX_MODIFIED)) {
return Promise.reject
("Selected staging is only available on modified files.");
}

return diff.patches();
return NodeGit.Status.file(repo, filePath)
.then(function(status) {
if (!(status & NodeGit.Status.STATUS.WT_MODIFIED) &&
!(status & NodeGit.Status.STATUS.INDEX_MODIFIED)) {
return Promise.reject
("Selected staging is only available on modified files.");
}
return diff.patches();
});
})
.then(function(patches) {
var pathPatch = patches.filter(function(patch) {
Expand Down Expand Up @@ -217,23 +217,26 @@ function performRebase(
function getPromise() {
return rebase.next()
.then(function() {
return repository.refreshIndex()
.then(function(index) {
if (index.hasConflicts()) {
throw index;
}
return repository.refreshIndex();
})
.then(function(index) {
if (index.hasConflicts()) {
throw index;
}

rebase.commit(null, signature);
return rebase.commit(null, signature);
})
.then(function() {

return performRebase(
repository,
rebase,
signature,
beforeNextFn,
beforeFinishFn
);
});
}, function(error) {
return performRebase(
repository,
rebase,
signature,
beforeNextFn,
beforeFinishFn
);
})
.catch(function(error) {
if (error && error.errno === NodeGit.Error.CODE.ITEROVER) {
const calcRewritten = fp.flow([
fp.split("\n"),
Expand Down Expand Up @@ -435,6 +438,7 @@ Repository.prototype.continueRebase = function(

signature = signature || repo.defaultSignature();

var rebase;
return repo.refreshIndex()
.then(function(index) {
if (index.hasConflicts()) {
Expand All @@ -443,9 +447,17 @@ Repository.prototype.continueRebase = function(

return NodeGit.Rebase.open(repo);
})
.then(function(rebase) {
rebase.commit(null, signature);

.then(function(_rebase) {
rebase = _rebase;
return rebase.commit(null, signature)
.catch(function() {
// Ignore all errors to prevent
// this routine from choking now
// that we made rebase.commit
// asynchronous
});
})
.then(function() {
return performRebase(
repo,
rebase,
Expand Down Expand Up @@ -1636,17 +1648,36 @@ Repository.prototype.stageFilemode =
})
.then(function(diff) {
var origLength = filePaths.length;
filePaths = filePaths.filter(function(p) {
return (
(NodeGit.Status.file(repo, p) & NodeGit.Status.STATUS.WT_MODIFIED) ||
(NodeGit.Status.file(repo, p) & NodeGit.Status.STATUS.INDEX_MODIFIED)
);
});
if (filePaths.length === 0 && origLength > 0) {
return Promise.reject
("Selected staging is only available on modified files.");
}
return diff.patches();
var fileFilterPromises = fp.map(function(p) {
return NodeGit.Status.file(repo, p)
.then(function(status) {
return {
path: p,
filter: (
(status & NodeGit.Status.STATUS.WT_MODIFIED) ||
(status & NodeGit.Status.STATUS.INDEX_MODIFIED)
)
};
});
}, filePaths);

return Promise.all(fileFilterPromises)
.then(function(results) {
filePaths = fp.flow([
fp.filter(function(filterResult) {
return filterResult.filter;
}),
fp.map(function(filterResult) {
return filterResult.path;
})
])(results);

if (filePaths.length === 0 && origLength > 0) {
return Promise.reject
("Selected staging is only available on modified files.");
}
return diff.patches();
});
})
.then(function(patches) {
var pathPatches = patches.filter(function(patch) {
Expand Down
4 changes: 1 addition & 3 deletions test/tests/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -1539,9 +1539,7 @@ describe("Merge", function() {
.then(function(theirAnnotatedCommit) {
return NodeGit.Merge(repository, theirAnnotatedCommit);
})
.then(function(result) {
assert.equal(result, 0);

.then(function() {
assert.equal(repository.state(),
NodeGit.Repository.STATE.MERGE);
// verify the convenience method
Expand Down
2 changes: 1 addition & 1 deletion test/tests/rebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ describe("Rebase", function() {
});
})
.then(function() {
return rebase.abort(ourSignature);
return rebase.abort();
})
.then(function() {
return NodeGit.Rebase.open(repository)
Expand Down