Skip to content

Commit 3600376

Browse files
committed
Fix Windows colors: %ENV instead of exec prefix
Tested with GitHub for Windows 1.0.36.0 using cmd, Powershell, and Git bash. Coloration worked properly in all three environments. Git bash threw a harmless "Unsuccessful stat on filename containing newline" warning, but otherwise worked. (I blame the ancient perl included with msysgit.) By adding a batch script launcher, we can thereby remove all the Windows caveat documentation in the README file. To use eg, simply put this directory in your path, even on Windows.
1 parent 65d4feb commit 3600376

File tree

3 files changed

+14
-42
lines changed

3 files changed

+14
-42
lines changed

README

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,6 @@ on each subcommand; for example, running
99
eg help commit
1010
will explain how to commit and provide many examples of doing so.
1111

12-
To Msysgit users [From Dan Fabulich]:
13-
1) Msysgit users aren't supplied an ordinary git.exe executable on
14-
the command-line, but a script called "git.cmd". Out of the box,
15-
"eg" can't find this script.
16-
17-
It's easy to update eg 0.99 to support a non-standard git executable
18-
(for example: my $git_cmd = "git.cmd"), but that'll get you in
19-
trouble...
20-
21-
2) ... because Perl's backtick (`) operator won't correctly detect
22-
the return code of git in that case; it'll think that git.cmd always
23-
returns 0. This confuses eg's revision-detector code, etc.
24-
25-
The only workaround I've found is to make a copy of git.cmd and
26-
change its behavior. git.cmd terminates the script using "@exit /b
27-
%ErrorLevel%"; I've made a copy called "gitx.cmd" that just uses
28-
"@exit %ErrorLevel%" and I refer to "gitx.cmd" in eg; that works
29-
perfectly.
30-
31-
3) eg assumes that you can set environment variables on the backtick
32-
command-line like this: `GIT_PAGER_IN_USE=1 git log -1` ... that
33-
works fine on UNIX but not on Windows.
34-
35-
I had to go through and comment out references to GIT_PAGER_IN_USE
36-
to get "eg log" to work. This disables color, but color is in a
37-
wonky state on msysgit anyway, so I scarcely miss it.
38-
39-
I think there's another clever use of inline environment variables
40-
in "eg revert"; it attempts to temporarily set GIT_INDEX_FILE when
41-
reverting just unstaged changes. I've never needed to do that, but
42-
I'm sure I will someday :-p
43-
44-
I assume these inline variables are being used to make them
45-
temporarily apply only to the child process? Would it be harmful to
46-
just set them as %ENV variables instead?
47-
(We should soon remove #3 from this README; I agree with Dan that we
48-
should just modify %ENV instead.)
49-
5012
Note: bash-completion-eg.sh is NOT needed to run eg; it's here just for
5113
the people that have bash completion set up and want to use it with eg
5214
(google for bash_completion if you want to know more or how to make use of

eg

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,8 +3300,12 @@ sub run {
33003300
$names{$revision} = [$branch, 0];
33013301

33023302
# Loop over the output of git log, printing/modifying as we go
3303-
my $use_colors = -t STDOUT ? "GIT_PAGER_IN_USE=1" : "";
3304-
open(INPUT, "$use_colors $git_cmd log @ARGV | ");
3303+
my $old_git_pager_in_use = $ENV{"GIT_PAGER_IN_USE"};
3304+
if (-t STDOUT) {
3305+
# use colors
3306+
$ENV{"GIT_PAGER_IN_USE"} = "1";
3307+
}
3308+
open(INPUT, "$git_cmd log @ARGV | ");
33053309
$ENV{"LESS"} = "FRSX" unless defined $ENV{"LESS"};
33063310
my $less = ($use_pager == 1) ? "less" :
33073311
($use_pager == 0) ? "cat" :
@@ -3330,6 +3334,7 @@ sub run {
33303334
my ($ret1, $ret2, $ret3);
33313335
close(INPUT); $ret1 = $? >> 8;
33323336
close(OUTPUT); $ret2 = $? >> 8;
3337+
$ENV{"GIT_PAGER_IN_USE"} = $old_git_pager_in_use;
33333338

33343339
# Make sure we close the pipe from rev-list too; We use "$? && $!"
33353340
# instead of "$?" because we don't care about the return value of the
@@ -5408,15 +5413,17 @@ sub run {
54085413

54095414
if (@other_files || !$paths_specified) {
54105415
my ($tmp_index) = Util::quote_args("$git_dir/tmp_index");
5411-
my $git_index = "GIT_INDEX_FILE=$tmp_index ";
54125416

54135417
my $cf = "@other_files";
54145418
if (!$paths_specified) {
54155419
my ($cur_dir, $top_dir, $git_dir) = RepoUtil::get_dirs();
54165420
($cf) = Util::reroot_paths__from_to_files($top_dir, $cur_dir, '.');
54175421
}
5418-
$ret = ExecUtil::execute("$git_index $git_cmd checkout $revision " .
5422+
my $old_git_index_file = $ENV{"GIT_INDEX_FILE"};
5423+
$ENV{"GIT_INDEX_FILE"} = $tmp_index;
5424+
$ret = ExecUtil::execute("$git_cmd checkout $revision " .
54195425
"-- $cf", ignore_ret => 1);
5426+
$ENV{"GIT_INDEX_FILE"} = $old_git_index_file;
54205427
exit $ret if $ret;
54215428

54225429
$ret = ExecUtil::execute("rm $tmp_index");

eg.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@echo off
2+
perl eg %*
3+
exit /b %errorlevel%

0 commit comments

Comments
 (0)