Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions 47 generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,53 @@
}
}
},
"rebase": {
"functions": {
"git_rebase_commit": {
"args": {
"id": {
"isReturn": true,
"shouldAlloc": true
},
"author": {
"isOptional": true
},
"message_encoding": {
"isOptional": true
},
"message": {
"isOptional": true
}
}
},
"git_rebase_finish": {
"args": {
"signature": {
"isOptional": true
}
}
},
"git_rebase_free": {
"ignore": true
},
"git_rebase_init": {
"args": {
"upstream": {
"isOptional": true
},
"onto": {
"isOptional": true
},
"signature": {
"isOptional": true
},
"opts": {
"isOptional": true
}
}
}
}
},
"refdb": {
"functions": {
"git_refdb_backend_fs": {
Expand Down
27 changes: 26 additions & 1 deletion 27 generate/input/libgit2-supplement.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@
},
"new" : {
"functions": {
"git_rebase_next": {
"type": "function",
"file": "rebase.h",
"args": [
{
"name": "out",
"type": "git_rebase_operation **"
},
{
"name": "rebase",
"type": "git_rebase *"
},
{
"name": "checkout_opts",
"type": "git_checkout_options *"
}
],
"return": {
"type": "int"
},
"group": "rebase"
},
"git_reset": {
"type": "function",
"file": "reset.h",
Expand Down Expand Up @@ -175,7 +197,7 @@
},
"groups": [
[
"annotated",
"annotated_commit",
[
"git_annotated_commit_free",
"git_annotated_commit_from_fetchhead",
Expand Down Expand Up @@ -498,6 +520,9 @@
}
},
"groups": {
"rebase": [
"git_rebase_next"
],
"reset": [
"git_reset"
],
Expand Down
23 changes: 23 additions & 0 deletions 23 lib/rebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var NodeGit = require("../");
var Rebase = NodeGit.Rebase;
var normalizeOptions = NodeGit.Utils.normalizeOptions;

// Override Rebase.prototype.finish to normalize opts
var finish = Rebase.prototype.finish;
Rebase.prototype.finish = function(signature, opts) {
opts = normalizeOptions(opts || {}, NodeGit.RebaseOptions);
return finish.call(this, signature, opts);
};

// Override Rebase.prototype.next to normalize opts and provide good defaults
var next = Rebase.prototype.next;
Rebase.prototype.next = function(checkoutOpts) {
if (!checkoutOpts) {
checkoutOpts = {
checkoutStrategy: NodeGit.Checkout.STRATEGY.SAFE_CREATE
};
}

checkoutOpts = normalizeOptions(checkoutOpts, NodeGit.CheckoutOptions);
return next.call(this, checkoutOpts);
};
111 changes: 111 additions & 0 deletions 111 lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -747,6 +747,117 @@ Repository.prototype.mergeBranches = function(to, from, signature) {
});
};

/**
* Goes through a rebase's rebase operations and commits them if there are
* no merge conflicts
*
* @param {Repository} repository The repository that the rebase is being
* performed in
* @param {Rebase} rebase The current rebase being performed
* @param {Signature} signature Identity of the one performing the rebase
* @return {Int|Index} An error code for an unsuccesful rebase or an index for
* a rebase with conflicts
*/
function performRebase(repository, rebase, signature) {
return rebase.next()
.then(function(rebaseOperation) {
return repository.openIndex()
.then(function(index) {
if (index.hasConflicts()) {
throw index;
}

if (rebaseOperation) {
rebase.commit(null, signature);

return performRebase(repository, rebase, signature);
}

return rebase.finish(signature);
});
});
}

/**
* Rebases a branch onto another branch
*
* @param {String} branch
* @param {String} upstream
* @param {String} onto
* @param {Signature} signature Identity of the one performing the rebase
* @return {Oid|Index} A commit id for a succesful merge or an index for a
* rebase with conflicts
*/
Repository.prototype.rebaseBranches = function(
branch,
upstream,
onto,
signature)
{
var repo = this;

signature = signature || repo.defaultSignature();

return Promise.all([
repo.getReference(branch),
upstream ? repo.getReference(upstream) : null,
onto ? repo.getReference(upstream) : null
])
.then(function(refs) {
return Promise.all([
NodeGit.AnnotatedCommit.fromRef(repo, refs[0]),
upstream ? NodeGit.AnnotatedCommit.fromRef(repo, refs[1]) : null,
onto ? NodeGit.AnnotatedCommit.fromRef(repo, refs[2]) : null
]);
})
.then(function(annotatedCommits) {
return NodeGit.Rebase.init(repo, annotatedCommits[0], annotatedCommits[1],
annotatedCommits[2], signature, null);
})
.then(function(rebase) {
return performRebase(repo, rebase, signature);
})
.then(function(error) {
if (error) {
throw error;
}

return repo.getBranchCommit("HEAD");
});
};

/**
* Continues an existing rebase
*
* @param {Signature} signature Identity of the one performing the rebase
* @return {Oid|Index} A commit id for a succesful merge or an index for a
* rebase with conflicts
*/
Repository.prototype.continueRebase = function(signature) {
var repo = this;

return repo.openIndex()
.then(function(index) {
if (index.hasConflicts()) {
throw index;
}

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

return performRebase(repo, rebase, signature);
})
.then(function(error) {
if (error) {
throw error;
}

return repo.getBranchCommit("HEAD");
});
};

// Override Repository.initExt to normalize initoptions
var initExt = Repository.initExt;
Repository.initExt = function(repo_path, opts) {
Expand Down
8 changes: 6 additions & 2 deletions 8 lib/utils/normalize_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ var NodeGit = require("../../");
* @return {Object} An Oid instance.
*/
function normalizeOptions(options, Ctor) {
var instance = options instanceof Ctor ? options : new Ctor();

if (!options) {
return null;
}

if (options instanceof Ctor) {
return options;
}

var instance = new Ctor();

Object.keys(options).forEach(function(key) {
instance[key] = options[key];
});
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.