-
Notifications
You must be signed in to change notification settings - Fork 699
Enable git_stash_foreach
#495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
omg....
There was a problem hiding this comment.
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: