From: "Gustavo L. de M. Chaves" <gnustavo@cpan.org>
To: git@vger.kernel.org
Cc: "Gustavo L. de M. Chaves" <gnustavo@cpan.org>
Subject: [PATCH 2/7] perl/Git.pm: set up command environment on Windows
Date: Wed, 30 Jan 2013 15:22:58 -0200 [thread overview]
Message-ID: <1359566583-19654-3-git-send-email-gnustavo@cpan.org> (raw)
In-Reply-To: <1359566583-19654-1-git-send-email-gnustavo@cpan.org>
From: "Gustavo L. de M. Chaves" <gnustavo@cpan.org>
Routine _cmd_exec invokes _setup_git_cmd_env inside the child process
before invoking an external git command to set up the environment
variables GIT_DIR and GIT_WORK_TREE and, also, to chdir to the
repository. But _cmd_exec is only used on Unix. On Windows, it's not
used and the main code path is in _command_common_pipe, which didn't
prepare the environment like _cmd_exec.
Without this environment preparation some git commands, such as "git
clone", don't work.
We can't use _setup_git_cmd_env in this case because we don't use a
forking open like _cmd_exec does and don't get a chance to make such
preparations on the child process.
So, the preparation is done on _command_common_pipe by setting up
localized environment variables and by chdir temporarily just before
invoking the external command.
Signed-off-by: Gustavo L. de M. Chaves <gnustavo@cpan.org>
---
perl/Git.pm | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/perl/Git.pm b/perl/Git.pm
index 658b602..e14b41a 100644
--- a/perl/Git.pm
+++ b/perl/Git.pm
@@ -1302,6 +1302,19 @@ sub _command_common_pipe {
# warn 'ignoring STDERR option - running w/ ActiveState';
$direction eq '-|' or
die 'input pipe for ActiveState not implemented';
+
+ # Set up repo environment
+ local $ENV{GIT_DIR} = $self->repo_path() if defined $self && $self->repo_path();
+ local $ENV{GIT_WORK_TREE} = $self->wc_path() if defined $self && $self->repo_path() && $self->wc_path();
+
+ my $cwd = cwd;
+
+ if (defined $self) {
+ chdir $self->repo_path() if $self->repo_path();
+ chdir $self->wc_path() if $self->wc_path();
+ chdir $self->wc_subdir() if $self->wc_subdir();
+ }
+
# the strange construction with *ACPIPE is just to
# explain the tie below that we want to bind to
# a handle class, not scalar. It is not known if
@@ -1310,6 +1323,7 @@ sub _command_common_pipe {
tie (*ACPIPE, 'Git::activestate_pipe', $cmd, @args);
$fh = *ACPIPE;
+ chdir $cwd;
} else {
my $pid = open($fh, $direction);
if (not defined $pid) {
--
1.7.12.464.g83379df.dirty
next prev parent reply other threads:[~2013-01-30 17:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-30 17:22 [PATCH 0/7] perl/Git.pm: a bunch of fixes for Windows Gustavo L. de M. Chaves
2013-01-30 17:22 ` [PATCH 1/7] perl/Git.pm: test portably if a path is absolute Gustavo L. de M. Chaves
2013-01-30 17:22 ` Gustavo L. de M. Chaves [this message]
2013-01-30 17:22 ` [PATCH 3/7] perl/Git.pm: fix _cmd_close on Windows Gustavo L. de M. Chaves
2013-01-30 17:23 ` [PATCH 4/7] perl/Git.pm: escape external command's arguments " Gustavo L. de M. Chaves
2013-01-30 17:23 ` [PATCH 5/7] perl/Git.pm: simplify Git::activestate_pipe Gustavo L. de M. Chaves
2013-01-30 17:23 ` [PATCH 6/7] perl/Git.pm: make command pipe work in slurp-mode on Windows Gustavo L. de M. Chaves
2013-01-30 17:23 ` [PATCH 7/7] perl/Git.pm: rename 'ActiveState' to 'Windows' Gustavo L. de M. Chaves
2013-02-25 6:54 ` [PATCH 0/7] perl/Git.pm: a bunch of fixes for Windows Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359566583-19654-3-git-send-email-gnustavo@cpan.org \
--to=gnustavo@cpan.org \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).