mirror of
https://github.com/git/git.git
synced 2026-08-04 15:11:09 +00:00
Merge branch 'ss/git-svn-prompt-sans-terminal' (early part) into next
* 'ss/git-svn-prompt-sans-terminal' (early part): perl/Git.pm: "prompt" helper to honor GIT_ASKPASS and SSH_ASKPASS
This commit is contained in:
20
git-svn.perl
20
git-svn.perl
@@ -4415,25 +4415,7 @@ sub username {
|
||||
|
||||
sub _read_password {
|
||||
my ($prompt, $realm) = @_;
|
||||
my $password = '';
|
||||
if (exists $ENV{GIT_ASKPASS}) {
|
||||
open(PH, "-|", $ENV{GIT_ASKPASS}, $prompt);
|
||||
$password = <PH>;
|
||||
$password =~ s/[\012\015]//; # \n\r
|
||||
close(PH);
|
||||
} else {
|
||||
print STDERR $prompt;
|
||||
STDERR->flush;
|
||||
require Term::ReadKey;
|
||||
Term::ReadKey::ReadMode('noecho');
|
||||
while (defined(my $key = Term::ReadKey::ReadKey(0))) {
|
||||
last if $key =~ /[\012\015]/; # \n\r
|
||||
$password .= $key;
|
||||
}
|
||||
Term::ReadKey::ReadMode('restore');
|
||||
print STDERR "\n";
|
||||
STDERR->flush;
|
||||
}
|
||||
my $password = Git::prompt($prompt);
|
||||
$password;
|
||||
}
|
||||
|
||||
|
||||
51
perl/Git.pm
51
perl/Git.pm
@@ -58,7 +58,7 @@ require Exporter;
|
||||
command_output_pipe command_input_pipe command_close_pipe
|
||||
command_bidi_pipe command_close_bidi_pipe
|
||||
version exec_path html_path hash_object git_cmd_try
|
||||
remote_refs
|
||||
remote_refs prompt
|
||||
temp_acquire temp_release temp_reset temp_path);
|
||||
|
||||
|
||||
@@ -512,6 +512,55 @@ C<git --html-path>). Useful mostly only internally.
|
||||
sub html_path { command_oneline('--html-path') }
|
||||
|
||||
|
||||
=item prompt ( PROMPT )
|
||||
|
||||
Query user C<PROMPT> and return answer from user.
|
||||
|
||||
If an external helper is specified via GIT_ASKPASS or SSH_ASKPASS, it
|
||||
is used to interact with the user; otherwise the prompt is given to
|
||||
and the answer is read from the terminal.
|
||||
|
||||
=cut
|
||||
|
||||
sub prompt {
|
||||
my ($prompt) = @_;
|
||||
my $ret;
|
||||
if (!defined $ret) {
|
||||
$ret = _prompt($ENV{'GIT_ASKPASS'}, $prompt);
|
||||
}
|
||||
if (!defined $ret) {
|
||||
$ret = _prompt($ENV{'SSH_ASKPASS'}, $prompt);
|
||||
}
|
||||
if (!defined $ret) {
|
||||
$ret = '';
|
||||
print STDERR $prompt;
|
||||
STDERR->flush;
|
||||
require Term::ReadKey;
|
||||
Term::ReadKey::ReadMode('noecho');
|
||||
while (defined(my $key = Term::ReadKey::ReadKey(0))) {
|
||||
last if $key =~ /[\012\015]/; # \n\r
|
||||
$ret .= $key;
|
||||
}
|
||||
Term::ReadKey::ReadMode('restore');
|
||||
print STDERR "\n";
|
||||
STDERR->flush;
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
|
||||
sub _prompt {
|
||||
my ($askpass, $prompt) = @_;
|
||||
return unless ($askpass);
|
||||
|
||||
open my $fh, "-|", $askpass, $prompt
|
||||
or return;
|
||||
my $ret = <$fh>;
|
||||
$ret =~ s/[\012\015]//g; # \n\r
|
||||
close ($fh);
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
=item repo_path ()
|
||||
|
||||
Return path to the git repository. Must be called on a repository instance.
|
||||
|
||||
Reference in New Issue
Block a user