stephenlacy / gulp-git Goto Github PK
View Code? Open in Web Editor NEWGit plugin for gulp (gulpjs.com)
License: MIT License
Git plugin for gulp (gulpjs.com)
License: MIT License
Sorry if this is a silly issue, but I haven't been able to find any other info about to how to solve this.
When I run a task with gulp-git
, I get the error ReferenceError: git is not defined
Sounds like it can't find git
, which would make sense except that I if I type git
in Terminal (Mac OS X 10.10) in the same directory, it works just fine. So perhaps the child_process
module is using a different environment / path to my user.
Is there a particular path I need to add git to in order to make it work? I'm not sure exactly where it is installed or how to debug this further.
Thanks for the help, and the excellent package :)
I'm looking to retrieve the current branch and hash during a build. Are you open to a PR that changes #branch
to return the current branch if none is passed?
Windows just doesn't support the $'foo' escaping that you can use on bash-like shells, so everything fails spectacularly when trying to e.g. add a file to index.
I've forked the shell-escape module and tried to make it more generic. It supposed to work on both Windows and bash/zsh now, but still not on every POSIX shell (it doesn't work on csh or dash, for instance).
I'm trying to simply commit then push, using:
// commit new version and push it
gulp.task('release', function() {
var version = require('./package.json').version;
return gulp.src('.')
.pipe(git.commit('released version ' + version))
.pipe(git.push('origin', 'master'))
.end();
});
This outputs:
$ npm run release
[gulp] Using gulpfile ~/gulpfile.js
[gulp] Starting 'release'...
[gulp] Finished 'release' after 16 ms
[gulp] [master ec170a6] released version 1.0.4
2 files changed, 4 insertions(+), 3 deletions(-)
[gulp] Everything up-to-date
Notice the last line - git push
is refusing to act because it sees nothing to do. It's not seeing the result of the commit.
A git log
confirms origin is behind:
* ec170a6 (HEAD, master) released version 1.0.4
* a86987c (origin/master, origin/HEAD) released version 1.0.3
I'm having trouble getting git.push to work.
I also can't seem to find any tests cases for the push.js.
It seems that return through.obj(write, flush);
might be the problem, since the private flush function isn't getting called.
https://github.com/stevelacy/gulp-git/blob/master/lib/push.js#L28
There are some cases where raw commit arguments might be passed in. Although requiring a commit message is a sensible default, it would be nice to have an option to override this check.
The code would look something like this assuming that commitArgs is the raw arguments to go to git commit:
.pipe(git.commit(undefined, {args: commitArgs, disableMessageRequirement: true}))
It looks like this hasn't worked for awhile (since before the 0.5.1 refactor). I've been chasing this for awhile and the commit
method simply doesn't resolve in a way that gets gulp to fire an end
event. This is fine, but if it doesn't fire end
it should at least accept a callback like some of the other tasks.
The docs seem to imply end
is fired (by returning the stream).
The lack of callback or end
make it impossible to orchestrate synchronous tasks which depend on commit
.
Here's a quick example using bluebird promises to commit then tag:
var q = require('bluebird');
function commit (src) {
return new q(function (resolve, reject) {
gulp
.src(src)
.pipe(git.commit('msg'))
.on('error', reject)
.on('end', resolve);
});
}
function tag () {
return new q(function (resolve, reject) {
git.tag('v0.0.1', 'tag', function(err) {
if (err) return reject(err);
resolve();
});
});
}
commit('./something').then(tag).catch(errHandler);
In this case, tag
never fires. errHandler
will fire if there is in fact an error.
There really has to be a way to hook into commit
. One way would be to pass a callback as in other tasks. Additionally, these commands could all accept an 'end'
option which tells them to fire end when they complete. This would obviously just call stream.resume()
if true;
For example, the above can be made to work:
function commit (src) {
var stream;
return new q(function (resolve, reject) {
gulp.src(src)
.pipe(stream = git.commit('msg'))
.on('error', reject)
.on('end', resolve);
stream.resume();
});
}
Finally, I realize that the above can be accomplished simply by piping commit
to tag
, and I'm sure this works for most cases. However, having this flexibility is nice. More importantly, it's the sort of flexibility that you'd expect to have simply due to the fact that so many other commands have a callback param. With most gulp tasks, it's sort of implied that gulp.dest()
will be called, which takes care of stream.resume()
, but gulp.dest()
doesn't really make sense here. Thus, I think makes sense to have solid hooks into the streams' lifecycle.
Let me know your thoughts and if you're amenable, I'll open a pull request.
This tool sounds too good to be true! Would there be a way to do $git add . $git commit -m "Your Msg here" and $git push in one command? If so, this is the greatest thing I've seen in a LONG time!
Thank you!
Getting fatal: Unable to create '/Users/justin/Sites/myapp/.git/index.lock': File exists.
I am using oh-my-zsh
which has git integration, could that be the issue?
gulp.task('gh-pages', function() {
return gulp.src('./*')
.pipe(git.checkout('gh-pages'));
});
I'm trying to create an orphaned branch so that I can create a gh-pages
branch for my project. I see in the source that the flags for the checkout command are being added after the branch name. Perhaps if the order were reversed it would be possible to include support for flags like -b
and --orphan
?
Would it be possible to implement git status into this module?
It would be useful for our team if there is some feedback form the repo if there are files not committed
Not sure if I am doing something wrong here. Just testing the commit task at this point.
In a new project I do git init
and git add .
in the cli. git status
shows files ready to be commited.
So I run gulp commit
and get the following errors
λ gulp commit
[gulp] Using file C:\Users\lotus\projects\gulpjscs\gulpfile.js
[gulp] Working directory changed to C:\Users\lotus\projects\gulpjscs
[gulp] Running 'commit'...
[gulp] Finished 'commit' in 4.79 ms
[gulp] { [Error: Command failed: error: pathspec 'commit'' did not match any file(s) known to git.
] killed: false, code: 1, signal: null }
[gulp] error: pathspec 'commit'' did not match any file(s) known to git.
[gulp] { [Error: Command failed: error: pathspec 'commit'' did not match any file(s) known to git.
] killed: false, code: 1, signal: null }
[gulp] error: pathspec 'commit'' did not match any file(s) known to git.
[gulp] { [Error: Command failed: error: pathspec 'commit'' did not match any file(s) known to git.
error: pathspec 'node_modules' did not match any file(s) known to git.
] killed: false, code: 1, signal: null }
[gulp] error: pathspec 'commit'' did not match any file(s) known to git.
error: pathspec 'node_modules' did not match any file(s) known to git.
[gulp] { [Error: Command failed: error: pathspec 'commit'' did not match any file(s) known to git.
] killed: false, code: 1, signal: null }
[gulp] error: pathspec 'commit'' did not match any file(s) known to git.
Here is the task
// Run git commit
gulp.task('commit', function(){
gulp.src('./*')
.pipe(git.commit('initial commit'));
});
This is on Windows in case that has anything to do with it.
It would be more gulp-like for tag to accept a stream, similar to how gulp-tag-version
accepts a stream. It assumes that the incoming stream is JSON with a top-level version
property which is used.
Couple this with making message optional (with a reasonable default) would make a more terse use-case possible: .pipe(tag())
First, excellent gulp plugin! Really helpful and useful so thanks for your effort.
Second, is it possible to add support for 'git config' to the plugin?
Here's the git man page for it: http://git-scm.com/docs/git-config
Here's an example of how it could be used:
git.config({args: 'core.sparsecheckout true'}, function (err) {
if (err) throw err;
});
var git = require('gulp-git');
// Clone a remote repo
gulp.task('clone', function(){
git.clone('https://git-location', './apps/');
});
This one is running but it is creating an undefined folder and copying all the files there. Am I doing something wrong or is this possible?
This looks great. How would the auth work on Windows?
A blogpost mentioned git.push('origin', 'master', '--tags').end();
But that seems to be the wrong way.
Could you document how to do this?
I'll be pushing the code when I finish tweaking it.
… please! :)
So in git you can push all your tags like this:
git push origin --tags
I tried to achieve the same result using gulp-git like this:
gulp.task('tag-push', function () {
console.info('Pushing...');
return git.push('origin', {args: " --tags"}, function (err) {
console.info('In callback');
if (err) {
console.error(err);
throw err;
} else {
console.info('done!');
}
});
});
Output:
> gulp tag-push
[17:03:09] Using gulpfile gulpfile.js
[17:03:09] Starting 'tag-push'...
Pushing...
That's it! The function returns immediately and the callback is never called. No push is done.
The repository is private. Can that be the reason? What should I do?
I am starting affaid of using this library. Do you ever run code before commit? It seems you blindly pushing code never even manually tested!
git.commit does not fire end event.
recent fixes in master are not reflected in last published release?
They need to be executed on flush, not per file. Push is broken due to https://github.com/stevelacy/gulp-git/blob/master/lib/push.js#L13 since it doesn't return a stream and calls the command immediately
Related:
Usefull to get the latest tag.
git describe --abbrev=0 --tags
Hello from North Scottsdale!
Error: Command failed: C:\Windows\system32\cmd.exe /s /c "git commit -m "..."
"app.js" "app.js.map" lib "package.json" routes "lib/database.js" "lib/database.
js.map" "routes/api.js" "routes/api.js.map""
Pretty sure a different escape method needs to be taken for this to work on Windows.
I'm running this task directly:
gulp.task('cbf', function() {
gulp.src(['public/app.min.js', 'public/app.min.css'])
.pipe(git.add())
.pipe(git.commit('Minified scripts for production'));
});
It works but I get a few error messages in the console until the task finishes succesfully:
➜ test git:(master) ✗ gulp cbf
[gulp] Using file /Users/Svilen/Development/test/gulpfile.js
[gulp] Working directory changed to /Users/Svilen/Development/test
[gulp] Running 'cbf'...
[gulp] Finished 'cbf' in 6 ms
[gulp]
[gulp]
[gulp] { [Error: Command failed: fatal: Unable to create '/Users/Svilen/Development/test/.git/index.lock': File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
] killed: false, code: 128, signal: null }
[gulp] fatal: Unable to create '/Users/Svilen/Development/test/.git/index.lock': File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
[gulp] { [Error: Command failed: ] killed: false, code: 1, signal: null }
I don't have anything else touching that git repository (apart from the lolcommits post-commit hook). The file .git/index.lock doesn't exist after the task finishes.
I run this Command npm install gulp -g
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npm-package-arg requires semver@'4' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/semver,
npm WARN unmet dependency which is version 2.0.8
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npm-install-checks requires npmlog@'0.1 || 1' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npmlog,
npm WARN unmet dependency which is version 0.0.3
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/readable-stream requires inherits@'~2.0.1' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/inherits,
npm WARN unmet dependency which is version 1.0.0
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npm-registry-client/node_modules/npm-package-arg requires semver@'4' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/semver,
npm WARN unmet dependency which is version 2.0.8
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npm-registry-client/node_modules/concat-stream requires inherits@'~2.0.1' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/inherits,
npm WARN unmet dependency which is version 1.0.0
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/npm-registry-client/node_modules/concat-stream/node_modules/readable-stream requires inherits@'~2.0.1' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/inherits,
npm WARN unmet dependency which is version 1.0.0
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/sha/node_modules/readable-stream requires inherits@'~2.0.1' but will load
npm WARN unmet dependency /usr/local/lib/node_modules/npm/node_modules/inherits,
npm WARN unmet dependency which is version 1.0.0
if i have deletions i cannot source them with glp.src, how can i commit them?
1/2 the tasks are great gulp plugins: take in a glob of vinyl files from gulp.src. 1/2 the tasks run in a directory and don't need a vinyl file, just a cwd. Split these two parts apart, make the first 1/2 'gulpplugin' and the second 1/2 'gulpfriendly'.
Hi there!
I'd like to say that your plugin is awesome! Thanks for that!!!
So, I'm trying to do a git commit --amend maintaining the same message as the current commit. So, the command fails because of the check of the message value:
mdesales@ubuntu ~/dev/github-intuit/sp-logging (master *) $ gulp patch
[11:37:32] Using gulpfile ~/dev/github-intuit/sp-logging/Gulpfile.js
[11:37:32] Starting 'patch'...
[11:37:32] 'patch' errored after 8.36 ms
[11:37:32] Error: gulp-git: Commit message is required git.commit("commit message")
Using an empty message will remove the current message because of plugin requires the message parameter as in https://github.com/stevelacy/gulp-git/blob/master/lib/commit.js#L26.
Using no message arguments and "--amend --no-edit" helps solving the problem. For instance,
mdesales@ubuntu ~/dev/github-intuit/sp-logging (master) $ git commit -a --amend --no-edit
[master 2722539] ISP-183, ISP-299: Mute logging of Intuit Headers in /health checks
3 files changed, 7 insertions(+), 3 deletions(-)
The API would change by accepting either undefined/null/empty message and the options.
...
...
.pipe(git.commit("", {args: "--amend"} ))
...
...
This committed pending changes by adding all the existing ones and amending the current commit without triggering the commit message editor.
I just run over second bug, which took me hours to investigate, because someone (you!) thinks is smart enough to write code without unit tests.
First one => #18 It would not happen with unit tests.
Second one => https://github.com/stevelacy/gulp-git/blob/master/lib/commit.js#L30
What's wrong with that line? Push accept more arguments.. and forEach callback pass not only file, but also index, etc.
So you are pushing file, its index, etc.
Common, be proffesional and write unit tests before code. It would save my time, your time, other people time. Thank you.
It would be really handy if there was a function to get the current branch name.
Hey guys, great lib!
I am having some trouble with the following scenrio. Checkout branch A, pull from branch B, commit any changes on branch A, push A, checkout B.
here is my task
gulp.task "tester", ->
gulp.src './'
.pipe git.checkout 'tester'
.pipe git.pull 'origin','dev'
.pipe git.add({args: '-A -v'})
.pipe git.commit 'Bundling for tester'
.pipe git.push()
.pipe git.checkout 'dev'
I get the following error
stream.js:79
dest.end();
^
TypeError: Object #<ChildProcess> has no method 'end'
Any ideas what I am doing wrong?
Thanks in adavance
Took inspiration from:
http://ponyfoo.com/articles/my-first-gulp-adventure
and tried this (just the checkin part for starters):
// tag and checkin to git
gulp.task('tag', function () {
var pkg = require('./package.json');
var v = 'v' + pkg.version;
var message = 'Release ' + v;
return gulp.src('./')
.pipe(git.commit(message));
});
and get error:
C:\eac>gulp tag
[21:26:25] Using gulpfile C:\eac\gulpfile.js
[21:26:25] Starting 'tag'...
[21:26:25] 'tag' errored after 46 ms
[21:26:25] Error: Command failed:
at ChildProcess.exithandler (child_process.js:648:15)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:756:16)
at Process.ChildProcess._handle.onexit (child_process.js:823:5)
which is Greek to me since I'm not a "gulp developer".
Does gulp-git work on Windows?
Hey,
Would you consider adding the following:
The simple git tag
looks a bit weak without being able to git release
it - as can be done in git extras.
Should be very easy to implement on Github through it's API.
Cheers
I'm in a situation where I'd like to have Gulp handle changing the remote origin. Using git remote add ...
fails due to origin already existing. This isn't an issue with set-url
. ie: git remote set-url origin https://url.com
However, for set-url
, origin has to exist, so there's still a need for addRemote.
Would be great to have git log
. Is it possible?
In my gulpfile I have
gulp.task 'git-add-all', ->
return gulp.src '*'
.pipe git.add { args: '--all' }
gulp.task 'git-commit', ->
return gulp.src '*'
.pipe git.commit "gulp autocommit"
When i do
gulp git-add-all && gulp git-commit
i'm getting
[16:22:56] 'git-commit' errored after 1.06 s
[16:22:56] Error: stdout maxBuffer exceeded.
at Socket.<anonymous> (child_process.js:699:13)
at Socket.emit (events.js:95:17)
at Socket.<anonymous> (_stream_readable.js:765:14)
at Socket.emit (events.js:92:17)
at emitReadable_ (_stream_readable.js:427:10)
at emitReadable (_stream_readable.js:423:5)
at readableAddChunk (_stream_readable.js:166:9)
at Socket.Readable.push (_stream_readable.js:128:10)
at Pipe.onread (net.js:529:21)
Is this a gulp-git
error or am i doing something wrong?
git.clone('https://github.com/Famous/famous.git',{args: './src/js/lib'});
I'm using the above it works or at least it seems to, large library I wouldn't know if it wasn't getting all of it. The problem is it throws quite a few errors I pasted them below.
[16:20:50] Using gulpfile ~/Programming/src/github.com/aintnorest/boiler-plate/gulpfile.js
[16:20:50] Starting 'initializeBuild'...
[16:20:50] 'initializeBuild' errored after 16 ms Object # has no method 'pipe'
[16:20:53] Cloning into './src/js/lib'...
/home/cjalatorre/Programming/src/github.com/aintnorest/boiler-plate/node_modules/gulp-git/lib/clone.js:19
cb();
^
TypeError: undefined is not a function
at /home/cjalatorre/Programming/src/github.com/aintnorest/boiler-plate/node_modules/gulp-git/lib/clone.js:19:5
at ChildProcess.exithandler (child_process.js:645:7)
at ChildProcess.emit (events.js:98:17)
at maybeClose (child_process.js:755:16)
at Process.ChildProcess._handle.onexit (child_process.js:822:5)
Leiningen has an useful command called lein vcs assert-committed
which ensures all is commited. How can this be done with this gulp plugin?
Hi, I am not sure if this is an issue, a new feature or just something I am doing wrong, but I am using gulp-git in a current project and have hit upon a problem. No matter where I try to include the extra arguments, I only get errors when I try to use --work-tree and --git-dir in my git task.
I have made various attempts at adding them as args or cwd, but no luck.
The command line request I am trying to recreate in gulp is:
git --git-dir=../git_repos/dev --work-tree=../dev status
I have asked a question on stackoverflow, just in case anyone there might no anything and that has the full details in it: http://stackoverflow.com/questions/29743031/using-gulp-git-how-to-use-git-dir-and-work-tree-when
ls-files has some handy flags, it would be good as a starting point for src files to feed into gulp. For example, if I wanted to copy non-git-ignored files to .build, I could do:
git.lsFiles({args: '--others -i --exclude-standard'})
.pipe(gulp.dest('.build'))
It would be very useful if this library supported promises, does anyone else find it useful? Basically if a cb isn't included in the call, it should return a promise that is resolved with something useful (or true) when the task is complete.
I'm trying to write a release task, which should bump the version, add the changed files to files, commit them and tag the commit. This is the code I wrote:
gulp.task('release', function () {
var version = semver.inc(require('./package.json').version, 'patch');
return gulp.src(['./package.json', './bower.json'])
.pipe($.bump({ version: version }))
.pipe(gulp.dest('./'))
.pipe($.git.add())
.pipe($.git.commit('chore(release): v' + version))
.pipe($.git.tag('v' + version, 'Version ' + version));
});
But somehow not the new but the commit before gets tagged. My git log looks like this:
* 30255da - chore(release): v0.0.2 — (HEAD, master)
* ec0d554 - init — (tag: v0.0.2)
I would have expected something like this:
* 30255da - chore(release): v0.0.2 — (HEAD, master, tag: v0.0.2)
* ec0d554 - init
Is this behavior expected or did I find a bug? And if it is by design, how could I solve my problem?
When the callback is missing an error is thrown, can someone explain to me how to make tagging work and then pushing?
I'm running gulp from within my dev project folder. After gulp copies my dev folder structure to to another folder on my filesystem I want to run git add. This is causing error;
gulp.task('add', ['minify-js'], function(){
return gulp.src('../hts_node_prod/*')
.pipe(git.add());
});
Logs:
[21:21:37] Starting 'move'...
[21:21:38] Finished 'move' after 524 ms
[21:21:38] Starting 'minify-css'...
[21:21:38] Finished 'minify-css' after 121 ms
[21:21:38] Starting 'minify-js'...
[21:21:38] Finished 'minify-js' after 682 ms
[21:21:38] Starting 'add'...
[21:21:38] 'add' errored after 23 ms
[21:21:38] Error: Command failed: fatal: /Library/WebServer/Documents/hts_node_prod/api: '/Library/WebServer/Documents/hts_node_prod/api' is outside repository
at ChildProcess.exithandler (child_process.js:637:15)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:735:16)
at Socket.<anonymous> (child_process.js:948:11)
at Socket.EventEmitter.emit (events.js:95:17)
at Pipe.close (net.js:466:12)
[21:21:38] fatal: /Library/WebServer/Documents/hts_node_prod/api: '/Library/WebServer/Documents/hts_node_prod/api' is outside repository
Thanks for help!
How could I get this to work with gulp-watch?
I am trying to use gulp-watch to pull from a git repo but couldn't manage to get it to work...
This snippet worked with 0.3.0.
gulp.src paths
.pipe bump type: type
.pipe gulp.dest './'
.on 'end', =>
version = require(path.join @dirname, 'package').version
message = "Bump #{version}"
gulp.src paths
.pipe git.add()
.pipe git.commit message
.on 'end', ->
git.push 'origin', 'master', {}, ->
git.tag version, message, {}, ->
git.push 'origin', 'master', args: ' --tags', done
return
And does not work anymore with 0.4.0. For some reason, .on 'end', -> after git.commit is not fired.
There are times when it may be preferable not to add paths to the end of the command string. Specifically if you are passing paths through raw args instead. In this case it is helpful to explicitly disable the paths via an option.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.