Skip to content

Commit

Permalink
Merge branch 'handle-custom-status-color'
Browse files Browse the repository at this point in the history
  • Loading branch information
nazri committed Jan 28, 2012
2 parents 364c47f + dd19a28 commit 92959da
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
5 changes: 3 additions & 2 deletions git-id
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -54,6 +54,7 @@ while (my $line = <$git_status>) {
}
}
print $line;
$line =~ s/\e\[\d*m//g;
print $cache $line;
}
close $git_status;
Expand Down
8 changes: 2 additions & 6 deletions git-list
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
38 changes: 38 additions & 0 deletions t/006_custom_status_color.t
Original file line number Diff line number Diff line change
@@ -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.