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: 2 additions & 2 deletions generate/input/callbacks.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@
},
{
"name": "stash_id",
"cType": "const int *"
"cType": "const git_oid *"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omg....

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't trust the docs :)

On Thu, Mar 19, 2015, 6:18 AM Tim Branyen [email protected] wrote:

In generate/input/callbacks.json
#495 (comment):

@@ -424,7 +424,7 @@
},
{
"name": "stash_id",

  •    "cType": "const int *"
    
  •    "cType": "const git_oid *"
    

omg....


Reply to this email directly or view it on GitHub
https://github.com/nodegit/nodegit/pull/495/files#r26752085.

},
{
"name": "payload",
Expand All @@ -433,7 +433,7 @@
],
"return": {
"type": "int",
"noResults": 1,
"noResults":0,
"success": 0,
"error": -1
}
Expand Down
5 changes: 4 additions & 1 deletion generate/input/descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,10 @@
"stash": {
"functions": {
"git_stash_foreach": {
"ignore": true
"isAsync": true,
"return": {
"isErrorCode": true
}
}
}
},
Expand Down
33 changes: 33 additions & 0 deletions generate/input/libgit2-supplement.json
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,36 @@
"type": "int"
},
"group": "reset"
},
"git_stash_save": {
"type": "function",
"file": "stash.h",
"args": [
{
"name": "out",
"type": "git_oid *"
},
{
"name": "repo",
"type": "git_repository *"
},
{
"name": "stasher",
"type": "const git_signature *"
},
{
"name": "message",
"type": "const char *"
},
{
"name": "flags",
"type": "unsigned int"
}
],
"return": {
"type": "int"
},
"group": "stash"
}
},
"groups": [
Expand Down Expand Up @@ -470,6 +500,9 @@
"groups": {
"reset": [
"git_reset"
],
"stash": [
"git_stash_save"
]
}
}
9 changes: 9 additions & 0 deletions lib/stash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var NodeGit = require("../");

var Stash = NodeGit.Stash;

// Override Stash.foreach to eliminate the need to pass null payload
var foreach = Stash.foreach;
Stash.foreach = function(repo, callback) {
return foreach(repo, callback, null);
};
87 changes: 87 additions & 0 deletions test/tests/stash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
var assert = require("assert");
var path = require("path");
var promisify = require("promisify-node");
var Promise = require("nodegit-promise");
var fse = promisify(require("fs-extra"));
var local = path.join.bind(path, __dirname);

describe("Stash", function() {
var NodeGit = require("../../");
var Repository = NodeGit.Repository;
var Stash = NodeGit.Stash;

var reposPath = local("../repos/workdir");

before(function() {
var test = this;
return Repository.open(reposPath)
.then(function(repository) {
test.repository = repository;
});
});

it("gets no stashes on clean working directory", function() {
var stashes = [];
var stashCb = function(index, message, oid) {
stashes.push({index: index, message: message, oid: oid});
};

return Stash.foreach(this.repository, stashCb)
.then(function() {
assert.equal(stashes.length, 0);
});
});

it("can save and drop a stash", function() {
var fileName = "README.md";
var fileContent = "Cha-cha-cha-chaaaaaangessssss";
var repo = this.repository;
var filePath = path.join(repo.workdir(), fileName);
var oldContent;
var stashes = [];
var stashOid;
var stashMessage = "stash test";

return fse.readFile(filePath)
.then(function(content) {
oldContent = content;
return fse.writeFile(filePath, fileContent);
})
.then(function() {
return Stash.save(repo, repo.defaultSignature(), stashMessage, 0);
})
.then(function(oid) {
stashOid = oid;
var stashCb = function(index, message, oid) {
stashes.push({index: index, message: message, oid: oid});
};

return Stash.foreach(repo, stashCb);
})
.then(function() {
assert.equal(stashes.length, 1);
assert.equal(stashes[0].index, 0);
assert.equal(stashes[0].message, "On master: " + stashMessage);
assert.equal(stashes[0].oid.toString(), stashOid.toString());

return Stash.drop(repo, 0);
})
.then(function () {
stashes = [];
var stashCb = function(index, message, oid) {
stashes.push({index: index, message: message, oid: oid});
};

return Stash.foreach(repo, stashCb);
})
.then(function() {
assert.equal(stashes.length, 0);
})
.catch(function(e) {
return fse.writeFile(filePath, oldContent)
.then(function() {
return Promise.reject(e);
});
});
});
});