Skip to content

Commit fb8c313

Browse files
committed
Add --not alias for --invert-match
This is easier to remember and works well grammatically with the command name. Signed-off-by: Kevin Locke <[email protected]>
1 parent 6a2afa6 commit fb8c313

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

bin/git-branch-is.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ function gitBranchIsCmd(args, callback) {
6565
.option('--git-path <path>', 'set the path to the git binary')
6666
.option('-i, --ignore-case', 'compare/match branch name case-insensitively')
6767
.option('-I, --invert-match', 'inverts/negates comparison')
68+
// Note: Commander.js only supports one long option per option call
69+
// https://github.com/tj/commander.js/issues/430
70+
.option('--not', 'inverts/negates comparison (same as --invert-match)')
6871
.option('-q, --quiet', 'suppress warning message if branch differs')
6972
.option('-r, --regex', 'match <branch name> as a regular expression')
7073
.option('-v, --verbose', 'print a message if the branch matches')
@@ -83,6 +86,9 @@ function gitBranchIsCmd(args, callback) {
8386
// pluralize --git-arg to cover multiple uses
8487
command.gitArgs = command.gitArg;
8588

89+
// treat --not as an alias for --invert-match
90+
command.invertMatch = command.invertMatch || command.not;
91+
8692
const expectedBranch = command.args[0];
8793

8894
let expectedBranchRegExp;

test/git-branch-is-cmd.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ describe('git-branch-is', () => {
340340
});
341341

342342
// Unlike an commands with expression arguments (e.g. find, test), follow
343-
// the typical argument convention that repeated flag arguments are ignored.
343+
// the convention that repeated flag arguments are ignored.
344344
it('does not double-invert', (done) => {
345345
const args = ARGS.concat('-I', '-I', 'invalid');
346346
gitBranchIsCmd(args, (err, result) => {
@@ -352,6 +352,29 @@ describe('git-branch-is', () => {
352352
});
353353
});
354354

355+
it('support --not as alias for -I', (done) => {
356+
const args = ARGS.concat('--not', 'invalid');
357+
gitBranchIsCmd(args, (err, result) => {
358+
assert.ifError(err);
359+
assert.strictEqual(result.code, 0);
360+
assert(!result.stdout);
361+
assert(!result.stderr);
362+
done();
363+
});
364+
});
365+
366+
// Careful that alias isn't handled differently
367+
it('does not double-invert with alias', (done) => {
368+
const args = ARGS.concat('-I', '--not', 'invalid');
369+
gitBranchIsCmd(args, (err, result) => {
370+
assert.ifError(err);
371+
assert.strictEqual(result.code, 0);
372+
assert(!result.stdout);
373+
assert(!result.stderr);
374+
done();
375+
});
376+
});
377+
355378
it('returns a Promise with the result', () => {
356379
const promise = gitBranchIsCmd(ARGS.concat(BRANCH_CURRENT));
357380
assert(promise instanceof global.Promise);

0 commit comments

Comments
 (0)