Comments (7)
Are there any flags which must go after the command?
from gulp-git.
No, the command in its entirety should be something like: git checkout --orphan gh-pages
.
I tried to do something like this:
gulp.src('.')
.pipe(git.checkout('--orphan gh-pages'));
No good.
It has something to do with the way the arguments are cleaned up and organized.
Here is the code as is:
module.exports = function (branch, opt) {
if(!opt) opt = {};
if(!branch) throw new Error('gulp-git: Branch name is require git.checkout("name")');
if(!opt.args) opt.args = ' ';
function checkout(file, cb) {
var cmd = "git checkout " + escape([branch]) + " " + opt.args;
exec(cmd, {cwd: file.cwd}, function(err, stdout, stderr){
if(err) cb(err);
gutil.log(stdout, stderr);
cb(null, file);
});
}
// Return a stream
return map(checkout);
};
Maybe, instead of using the flags passed in an object with only one property, it would be possible to leave it up to the user to put the flags in the correct place? That would add a little more openness to the API and be a little less restrictive.
Perhaps:
module.exports = function(args) {
if(!args) throw new Error("Must supply args.");
if(!Array.isArray(args)) args = [args];
function checkout(file, cb) {
var cmd = ["git checkout"].concat(args);
exec(cmd.join(" "), {cwd: file.cwd()}, function(err, stdout, stderr) {
...
Any thoughts on this?
from gulp-git.
A thought:
Would this be capable of solving the argument issue?
var cmd = "git checkout " + opt.args + " " + escape([branch]);
result:
$ git checkout --orphan test2
How would having the concat and join allow the user to place the args as the second word or end of sentence?
from gulp-git.
Hi Steve,
The reason is that unless you're specifically looking to handle only the most basic use cases for git, the order of the flags and arguments can't really be determined by hard-coding an order in when you develop your library. The concat and join is just an idea to allow them to use any order they want.
It would be used like this:
git.checkout('--orphan', 'branchname');
Or:
git.commit('-a', '-m \"initial commit\"');
(The '-a' flag goes before the message, throws an error if it goes after)
At the very least, I suppose you could wrap the entire cmd in the escape function? It might allow the workaround I mentioned before... I'll have to test it out. Otherwise, you'll have to accept all possible arguments and code in an order manually for every single use-case scenario. For branch alone, there are about twelve or so...
Just a thought, you could do both ways. I.e. Accept the args object and accept an array as the main argument. Seems a little redundant to me, but it would cover all use cases and make the API more flexible.
Here's what that might look like:
module.exports = function() {
var args = Array.prototype.slice.apply(arguments);
if(!args) throw new Error("Must supply args.");
var options, last = args.[args.length-1];
if(last === Object(last)) {
if(args.length < 1) throw new Error("Must supply something more than just an options object.");
options = args.pop();
}
else {
options = [];
}
function checkout(file, cb) {
var cmd = ["git checkout"].concat(args, options);
exec(cmd.join(" "), {cwd: file.cwd()}, function(err, stdout, stderr) {
...
from gulp-git.
Hi Steve,
The reason is that unless you're specifically looking to handle only the most basic use cases for git, the order of the flags and arguments can't really be determined by hard-coding an order in when you develop your library. The concat and join is just an idea to allow them to use any order they want.
It would be used like this:
git.checkout('--orphan', 'branchname');
Or:
git.commit('-a', '-m \"initial commit\"');
(The '-a' flag goes before the message, throws an error if it goes after)
At the very least, I suppose you could wrap the entire cmd in the escape function? It might allow the workaround I mentioned before... I'll have to test it out. Otherwise, you'll have to accept all possible arguments and code in an order manually for every single use-case scenario. For branch alone, there are about twelve or so...
Just a thought, you could do both ways. I.e. Accept the args object and accept an array as the main argument. Seems a little redundant to me, but it would cover all use cases and make the API more flexible.
Here's what that might look like:
module.exports = function() {
var args = Array.prototype.slice.apply(arguments);
if(!args) throw new Error("Must supply args.");
var options, last = args.[args.length-1];
if(last === Object(last)) {
if(args.length < 1) throw new Error("Must supply something more than just an options object.");
options = args.pop();
}
else {
options = [];
}
function checkout(file, cb) {
var cmd = ["git checkout"].concat(args, options);
exec(cmd.join(" "), {cwd: file.cwd()}, function(err, stdout, stderr) {
...
from gulp-git.
Wrapping the entire cmd in the escape function would end up with the arguments detected as strings, and quoted.
What if the arguments had a second flag to go before the command? such as 'preargs' and 'args' ?
from gulp-git.
Adding a 'preargs' option would unnecessarily complicate the API in my opinion. It's not entirely clear and it still doesn't allow for the full flexibility of git commands. If you were to go that route, it'd almost make more sense to hard-code certain flags in to allow for them, but then you'd have to modify the code often to allow for a lot of flags and Git updates.
On May 14, 2014, at 11:01 PM, Steve Lacy [email protected] wrote:
Wrapping the entire cmd in the escape function would end up with the arguments detected as strings, and quoted.
What if the arguments had a second flag to go before the command? such as 'preargs' and 'args' ?—
Reply to this email directly or view it on GitHub.
from gulp-git.
Related Issues (20)
- Get current branch name? HOT 2
- git add is broken in Node 8 HOT 1
- git.add does not allow for specified files to add in another cwd HOT 4
- gulp-git breaks in Node 9.5.0. HOT 3
- Error creating commit on new git version HOT 20
- Error: i can't commit HOT 2
- How to use git clone with ssh HOT 2
- How to clone with a specified branch? HOT 5
- commit() will commit also unstaged files HOT 2
- Git add . all files HOT 2
- Cannot use '-a' anymore for commit HOT 4
- how can I checkout a file HOT 1
- stdout maxBuffer length exceeded (diff.js) HOT 1
- Problem with absolute path or Gulp v4
- Cherry-pick - feature request HOT 1
- finish event listener registration error
- Gulp 4 compatibility HOT 1
- Add rebase command HOT 2
- "The command line is too long." on `git.add()` HOT 1
- lodash.template critical vulnerabilities from Mend HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gulp-git.