Permalink
Browse files

Merge branch 'handle-custom-status-color'

  • Loading branch information...
2 parents 364c47f + dd19a28 commit 92959da00f3a4438b070bad132e8bfb5787620d9 @nazri nazri committed Jan 28, 2012
Showing with 43 additions and 8 deletions.
  1. +3 −2 git-id
  2. +2 −6 git-list
  3. +38 −0 t/006_custom_status_color.t
View
5 git-id
@@ -43,8 +43,8 @@ print $cache "\n";
my $c = 1;
while (my $line = <$git_status>) {
if ($status_style == $STATUS_DEFAULT) {
- if ($line =~ /^#\t/) {
- $line =~ s/^#/#$c/;
+ if ($line =~ /#\t/) {
+ $line =~ s/#\t/#$c\t/;
$c += 1;
}
} elsif ($status_style == $STATUS_SHORT) {
@@ -54,6 +54,7 @@ while (my $line = <$git_status>) {
}
}
print $line;
+ $line =~ s/\e\[\d*m//g;
print $cache $line;
}
close $git_status;
View
@@ -82,10 +82,8 @@ sub get_file_list {
while (my $line = <$cache>) {
next if $line !~ /^#[0-9]+\t/;
chomp $line;
- my $line_nocolor = $line;
- $line_nocolor =~ s/\e[^m]+m//g;
if (my ($number, $status, $filename)
- = $line_nocolor =~ /^#([0-9]+)\t([^:]+:\s+)?(.*)/) {
+ = $line =~ /^#([0-9]+)\t([^:]+:\s+)?(.*)/) {
if ($filename =~ / \(.*\)$/ && ! -e $filename) {
# Looks like a submodule status, see if it really is a submodule
@@ -110,10 +108,8 @@ sub get_file_list {
while (my $line = <$cache>) {
next if $line !~ /^[0-9]+\s/;
chomp $line;
- my $line_nocolor = $line;
- $line_nocolor =~ s/\e[^m]+m//g;
if (my ($number, $status, $filename)
- = $line_nocolor =~ /^([0-9]+)\s+([^ ]+)\s+(.*)/) {
+ = $line =~ /^([0-9]+)\s+([^ ]+)\s+(.*)/) {
if ($needfixdir) {
$filename = fixdir($filename, $headers->{cwd}, $cwd);
@@ -0,0 +1,38 @@
+#!/usr/bin/env perl
+# vim:fdm=marker foldmarker={\:,\:}: commentstring=\ #%s
+use strict;
+use warnings;
+use Test::More tests => 1;
+
+use lib 't/lib';
+use Scaffold qw/$workdir $srcdir/;
+
+my $got;
+my $expected;
+my $testname;
+
+# Start from a clean slate
+Scaffold::init();
+
+$testname = "git number with custom status color"; #{:
+`
+cd $workdir &&
+echo 'one' > one.txt &&
+ git init &&
+ git add . &&
+ git config color.status.header 'normal dim'
+`;
+$got = `cd $workdir; $srcdir/git-number --color=always`;
+$got =~ s/\e\[\d*m//gs;
+$expected = <<EOT;
+# On branch master
+#
+# Initial commit
+#
+# Changes to be committed:
+# (use "git rm --cached <file>..." to unstage)
+#
+#1 new file: one.txt
+#
+EOT
+eq_or_diff($got, $expected, $testname); #:}

0 comments on commit 92959da

Please sign in to comment.