Skip to content

Commit

Permalink
Fixes #415 - branch names mangled by color escapes
Browse files Browse the repository at this point in the history
- add "-c color.branch=never" option to git branch commands, definitively disabling color branch output

.# Discussion

Branch names are mis-parsed if `git branch` output is colored (eg, when git is configured
with "config.branch=always"). Using the base "-c color.branch=never" option overrides any
user configuration, displaying git branch output as uncolored in all cases and fixing the
issue.

Notably, option ordering is important in this instance. The "-c ..." option is a git
base option, not a git branch subcommand option. So, as done here, it must be inserted
before the "branch" subcommand.

ref: Issue #415
  • Loading branch information
rivy authored and eamodio committed Jun 17, 2018
1 parent 8f30d0b commit 3991f4a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/git/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ export class Git {
}

static branch(repoPath: string, options: { all: boolean } = { all: false }) {
const params = ['branch', '-vv'];
const params = ['-c', 'color.branch=never', 'branch', '-vv'];
if (options.all) {
params.push('-a');
}
Expand All @@ -334,7 +334,7 @@ export class Git {
}

static branch_contains(repoPath: string, ref: string, options: { remote: boolean } = { remote: false }) {
const params = ['branch', '--contains'];
const params = ['-c', 'color.branch=never', 'branch', '--contains'];
if (options.remote) {
params.push('-r');
}
Expand Down

0 comments on commit 3991f4a

Please sign in to comment.