| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| 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); | ||
| }; |
| 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); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
| Back | FazBrowse Home | New Git URL |
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Qualityomg....
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityDon't trust the docs :)
On Thu, Mar 19, 2015, 6:18 AM Tim Branyen notifications@github.com wrote:
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.