Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/stevelacy/gulp-git
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenlacy committed Mar 7, 2015
2 parents c24cd8a + 8e13291 commit a742ed1
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,21 @@ gulp.task('pull', function(){
});
});

// Run git fetch
// Fetch refs from all remotes
gulp.task('fetch', function(){
git.fetch('', '', {args: '--all'}, function (err) {
if (err) throw err;
});
});

// Run git fetch
// Fetch refs from origin
gulp.task('fetch', function(){
git.fetch('origin', '', function (err) {
if (err) throw err;
});
});

// Clone a remote repo
gulp.task('clone', function(){
Expand Down Expand Up @@ -280,6 +295,25 @@ git.addRemote('origin', 'git-repo-url', function (err) {
});
```

### git.fetch(remote, branch, opt, cb)
`git fetch <remote> <branch>`

Fetches refs and objects from remote repo

`remote`: String, name of remote, default: `origin`

`branch`: String, branch, default: ``

`opt`: Object (optional) `{args: 'options', cwd: '/cwd/path', quiet: true}`

`cb`: function, passed err if any

```js
git.fetch('origin', '', function (err) {
//if (err) ...
});
```

### git.pull(remote, branch, opt, cb)
`git pull <remote> <branch>`

Expand Down
26 changes: 26 additions & 0 deletions lib/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

var gutil = require('gulp-util');
var exec = require('child_process').exec;
var escape = require('any-shell-escape');

module.exports = function (remote, branch, opt, cb) {
if (!cb && typeof opt === 'function') {
// optional options
cb = opt;
opt = {};
}
if (!cb || typeof cb !== 'function') cb = function () {};
if (!branch) branch = '';
if (!opt) opt = {};
if (!opt.cwd) opt.cwd = process.cwd();
if (!opt.args) opt.args = ' ';
if (!remote && opt.args.indexOf('--all') === -1) remote = 'origin';

var cmd = 'git fetch ' + opt.args + ' ' + escape([remote, branch]);
return exec(cmd, {cwd: opt.cwd}, function(err, stdout, stderr){
if (err) return cb(err);
if (!opt.quiet) gutil.log(stdout, stderr);
cb();
});
};
40 changes: 40 additions & 0 deletions test/fetch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

/* global describe, it, after, before, afterEach, beforeEach */

var fs = require('fs');
var rimraf = require('rimraf');
var should = require('should');
var exec = require('child_process').exec;

module.exports = function(git, util){


beforeEach(function(done){
var repo = 'git://github.com/stevelacy/git-test';
git.clone(repo, {args: './test/tmp'}, function(){
exec('git update-ref -d refs/tags/v1.1.1', {cwd: './test/tmp'}, function(err){
if (err) return done(err);
done();
});
});
});

it('should fetch a tag from remote origin', function(done){
git.fetch('origin', '', {cwd: './test/tmp'}, function(){
fs.open('./test/tmp/.git/refs/tags/v1.1.1', 'r', function(err, fd) {
should.not.exist(err);
fs.close(fd, function() {
done();
});
});
});
});

afterEach(function(done){
rimraf('./test/tmp', function(err){
if(err) return done(err);
done();
});
});
};

0 comments on commit a742ed1

Please sign in to comment.