Git-Server
view release on metacpan or search on metacpan
my ($op) = grep { /^(clone|fetch|pull|ls-remote|push)$/ } @ARGV;
return if !$op;
# Need to search for special "-o" options for XMODIFIERS transport
my $xmod = $ENV{XMODIFIERS} || "";
my @options = ();
my $pull_branch = "";
push @options, "DEBUG=$ENV{DEBUG}" if defined $ENV{DEBUG} and $xmod !~ /^DEBUG=/m;
if (eval { require Getopt::Long; 1; } and
Getopt::Long::GetOptions( "O=s" => \@options )) { # Strip stealth -O args from ARGV so the real git doesn't choke on it
if (my $rest_opt = ($op ne "clone" && "o|")."server-option|push-option=s") { # Ignore -o<origin> for "git clone"
local @ARGV = @ARGV; # Don't monkey anything. Just peek.
Getopt::Long::GetOptions( $rest_opt => \@options, "branch|b=s" => \$pull_branch ); # Handle "git clone -b <ref> <repo>"
}
}
$pull_branch = $1 if $op =~ /^(fetch|pull)$/ and $xmod !~ /^pull_branch=/m and git("branch") =~ m{^\* ([\w/\-.@]+)\s*$}m;
push @options, "pull_branch=$pull_branch" if $pull_branch;
push @options, "client=".abs_path($0)."\@v$VERSION" if $xmod !~ /^client=/m;
push @options, $xmod if $xmod;
$ENV{XMODIFIERS} = join "\n", @options;
$ENV{GIT_SSH_COMMAND} ||= git(qw[config core.sshCommand]) =~ /^(.+)/ ? $1 : "ssh";
$ENV{GIT_SSH_COMMAND} = "$ENV{GIT_SSH_COMMAND} -o SendEnv=XMODIFIERS";
}
}
else {
# No effective .gitconfig files found in descent, so nothing to do
}
}
# Special "config" handler to honor new --descent option
sub handle_config {
my @args = @_;
local @ARGV = @args;
# Don't try to handle the "--help"-first case.
return if join(" ", @ARGV) =~ /config --help\b/;
if (grep {$_ eq "config"} @ARGV and
# Smells like special "git config" command
eval { require Getopt::Long; 1; } and
Getopt::Long::Configure(qw[pass_through no_ignore_case require_order]) and
Getopt::Long::GetOptions( "c=s" => (my $c=[]) ) and # XXX: Is is safe to ignore -c <name>=<value> args?
$ARGV[0] eq "config" and
do {
# Handle naked "git config" case to make sure the usage can be updated before sending it
1;
} or eval {
require File::Which; # Try "dig" as last-ditch effort:
my $dig = File::Which::which("dig") or die "no dig";
$resolvable = `$dig +short $remotehost A $remotehost AAAA 2>/dev/null`;
1;
} or $resolvable = 1; # If IPv6 resolvers are unavailable, then assume it's valid, and just blindly run ssh
if ($resolvable) {
length()?$ARGV[0]=$_:shift;
$ENV{XMODIFIERS}="client=".abs_path($0)."\@v$VERSION";
my $search = q{$_=shift and 1+s/'/'"'"'/g and`(which '$_' git-verify|grep . || find . ~ /usr/local/bin /usr/bin /bin -name git-verify) 2>/dev/null`=~m{^(.+)}&&exec $1,@ARGV;warn"Cannot find git-verify on ".`hostname`."[$1][$!]['$_' @ARGV]...
pipe my $FAKE_STDIN, my $prog;
print $prog $search;
close $prog;
open STDIN, "<&", $FAKE_STDIN;
exec qw[ssh
-o PubKeyAuthentication=yes
-o KbdInteractiveAuthentication=no
-o PasswordAuthentication=no
-o SendEnv=XMODIFIERS
-p], $remoteport,
( run in 0.873 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )