Skip to content
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
4 changes: 4 additions & 0 deletions generate/input/libgit2-supplement.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,10 @@
"name": "prune",
"type": "git_fetch_prune_t"
},
{
"name": "proxy_opts",
"type": "git_proxy_options"
},
{
"name": "update_fetchhead",
"type": "int"
Expand Down
13 changes: 11 additions & 2 deletions generate/templates/templates/binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,22 @@
}
}
}
], [
],
[
"OS=='linux' or OS=='mac'", {
"libraries": [
"-lcurl"
]
}
],
[
"OS=='linux' and '<!(echo \"$CXX\")'=='clang++'", {
"cflags": [
"-Wno-c++11-extensions"
]
}
], [
],
[
"OS=='linux' and '<!(echo \"$CXX\")'!='clang++'", {
"cflags": [
"-std=c++0x"
Expand Down
1 change: 1 addition & 0 deletions generate/templates/templates/nodegit.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ rawApi.Utils = {};
require("./utils/lookup_wrapper");
require("./utils/normalize_options");
require("./utils/shallow_clone");
require("./utils/normalize_fetch_options");

// Load up extra types;
require("./status_file");
Expand Down
17 changes: 2 additions & 15 deletions lib/clone.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
var NodeGit = require("../");
var shallowClone = NodeGit.Utils.shallowClone;
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
var normalizeOptions = NodeGit.Utils.normalizeOptions;

var Clone = NodeGit.Clone;
Expand All @@ -15,29 +16,15 @@ var _clone = Clone.clone;
* @return {Repository} repo
*/
Clone.clone = function(url, local_path, options) {
var remoteCallbacks = {};
var fetchOpts = {};
var fetchOpts = normalizeFetchOptions(options && options.fetchOpts);

if (options) {
options = shallowClone(options);
if (options.fetchOpts) {
fetchOpts = shallowClone(options.fetchOpts);
}
delete options.fetchOpts;
}

options = normalizeOptions(options, NodeGit.CloneOptions);

if (fetchOpts.callbacks) {
remoteCallbacks = shallowClone(fetchOpts.callbacks);
delete fetchOpts.callbacks;
}

fetchOpts = normalizeOptions(fetchOpts, NodeGit.FetchOptions);

fetchOpts.callbacks =
normalizeOptions(remoteCallbacks, NodeGit.RemoteCallbacks);

if (options) {
options.fetchOpts = fetchOpts;
}
Expand Down
76 changes: 54 additions & 22 deletions lib/remote.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var NodeGit = require("../");
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var lookupWrapper = NodeGit.Utils.lookupWrapper;
var shallowClone = NodeGit.Utils.shallowClone;
Expand All @@ -8,6 +9,7 @@ var _connect = Remote.prototype.connect;
var _download = Remote.prototype.download;
var _fetch = Remote.prototype.fetch;
var _push = Remote.prototype.push;
var _upload = Remote.prototype.upload;

/**
* Retrieves the remote by name
Expand Down Expand Up @@ -53,24 +55,8 @@ Remote.prototype.connect = function(
* @return {Number} error code
*/
Remote.prototype.download = function(refspecs, opts) {
var callbacks;

if (opts) {
opts = shallowClone(opts);
callbacks = opts.callbacks;
delete opts.callbacks;
} else {
opts = {};
}

opts = normalizeOptions(opts, NodeGit.FetchOptions);

if (callbacks) {
opts.callbacks =
normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
}

return _download.call(this, refspecs, opts);
return _download
.call(this, refspecs, normalizeFetchOptions(opts));
};

/**
Expand All @@ -84,24 +70,61 @@ Remote.prototype.download = function(refspecs, opts) {
* @return {Number} error code
*/
Remote.prototype.fetch = function(refspecs, opts, reflog_message) {
return _fetch
.call(this, refspecs, normalizeFetchOptions(opts), reflog_message);
};

/**
* Pushes to a remote
*
* @async
* @param {Array} refSpecs The ref specs that should be pushed
* @param {PushOptions} options Options for the checkout
* @param {Function} callback
* @return {Number} error code
*/
Remote.prototype.push = function(refSpecs, opts) {
var callbacks;
var proxyOpts;

if (opts) {
opts = shallowClone(opts);
callbacks = opts.callbacks;
proxyOpts = opts.proxyOpts;
delete opts.callbacks;
delete opts.proxyOpts;
} else {
opts = {};
}

opts = normalizeOptions(opts, NodeGit.FetchOptions);
opts = normalizeOptions(opts, NodeGit.PushOptions);

if (callbacks) {
opts.callbacks =
normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
}

return _fetch.call(this, refspecs, opts, reflog_message);
if (proxyOpts) {
opts.proxyOpts =
normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
}

return _push.call(this, refSpecs, opts);
};

/**
* Connects to a remote
*
* @async
* @param {Array} refSpecs The ref specs that should be pushed
* @param {FetchOptions} opts The fetch options for download, contains callbacks
* @param {String} message The message to use for the update reflog messages
* @param {Function} callback
* @return {Number} error code
*/
Remote.prototype.fetch = function(refspecs, opts, reflog_message) {
return _fetch
.call(this, refspecs, normalizeFetchOptions(opts), reflog_message);
};

/**
Expand All @@ -113,12 +136,16 @@ Remote.prototype.fetch = function(refspecs, opts, reflog_message) {
* @param {Function} callback
* @return {Number} error code
*/
Remote.prototype.push = function(refSpecs, opts) {
Remote.prototype.upload = function(refSpecs, opts) {
var callbacks;
var proxyOpts;

if (opts) {
opts = shallowClone(opts);
callbacks = opts.callbacks;
proxyOpts = opts.proxyOpts;
delete opts.callbacks;
delete opts.proxyOpts;
} else {
opts = {};
}
Expand All @@ -130,5 +157,10 @@ Remote.prototype.push = function(refSpecs, opts) {
normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
}

return _push.call(this, refSpecs, opts);
if (proxyOpts) {
opts.proxyOpts =
normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
}

return _upload.call(this, refSpecs, opts);
};
30 changes: 30 additions & 0 deletions lib/submodule.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
var NodeGit = require("../");
var normalizeFetchOptions = NodeGit.Utils.normalizeFetchOptions;
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var shallowClone = NodeGit.Utils.shallowClone;

var Submodule = NodeGit.Submodule;

var _foreach = Submodule.foreach;
var _update = Submodule.prototype.update;

// Override Submodule.foreach to eliminate the need to pass null payload
Submodule.foreach = function(repo, callback) {
return _foreach(repo, callback, null);
};

/**
* Updates a submodule
*
* @async
* @param {Number} init Setting this to 1 will initialize submodule
* before updating
* @param {SubmoduleUpdateOptions} options Submodule update settings
* @return {Number} 0 on success, any non-zero return value from a callback
*/
Submodule.prototype.update = function(init, options) {
var fetchOpts = normalizeFetchOptions(options && options.fetchOpts);

if (options) {
options = shallowClone(options);
delete options.fetchOpts;
}

options = normalizeOptions(options, NodeGit.SubmoduleUpdateOptions);

if (options) {
options.fetchOpts = fetchOpts;
}

return _update.call(this, init, options);
};
43 changes: 43 additions & 0 deletions lib/utils/normalize_fetch_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var NodeGit = require("../../");
var normalizeOptions = NodeGit.Utils.normalizeOptions;
var shallowClone = NodeGit.Utils.shallowClone;

/**
* Normalize an object to match a struct.
*
* @param {String, Object} oid - The oid string or instance.
* @return {Object} An Oid instance.
*/
function normalizeFetchOptions(options) {
if (options instanceof NodeGit.FetchOptions) {
return options;
}

var callbacks;
var proxyOpts;

if (options) {
options = shallowClone(options);
callbacks = options.callbacks;
proxyOpts = options.proxyOpts;
delete options.callbacks;
delete options.proxyOpts;
} else {
options = {};
}

options = normalizeOptions(options, NodeGit.FetchOptions);

if (callbacks) {
options.callbacks =
normalizeOptions(callbacks, NodeGit.RemoteCallbacks);
}

if (proxyOpts) {
options.proxyOpts =
normalizeOptions(proxyOpts, NodeGit.ProxyOptions);
}
return options;
}

NodeGit.Utils.normalizeFetchOptions = normalizeFetchOptions;
10 changes: 10 additions & 0 deletions vendor/libgit2.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@
"libgit2/src/config_file.h",
"libgit2/src/config.c",
"libgit2/src/config.h",
"libgit2/src/curl_stream.c",
"libgit2/src/curl_stream.h",
"libgit2/src/crlf.c",
"libgit2/src/date.c",
"libgit2/src/delta-apply.c",
Expand Down Expand Up @@ -277,6 +279,14 @@
}
}
}],
["OS=='mac' or OS=='linux' or OS.endswith('bsd')", {
"cflags": [
"-DGIT_CURL"
],
"defines": [
"GIT_CURL"
]
}],
["OS=='linux' or OS.endswith('bsd')" , {
"cflags": [
"-DGIT_SSH",
Expand Down