Skip to content

Commit 6053bf6

Browse files
committed
Merge branch 'msys2'
2 parents 7719206 + a77944a commit 6053bf6

File tree

3 files changed

+61
-49
lines changed

3 files changed

+61
-49
lines changed

compat/terminal.c

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,55 @@ static int getchar_with_timeout(int timeout)
419419
return getchar();
420420
}
421421

422+
static char *shell_prompt(const char *prompt, int echo)
423+
{
424+
const char *read_input[] = {
425+
/* Note: call 'bash' explicitly, as 'read -s' is bash-specific */
426+
"bash", "-c", echo ?
427+
"cat >/dev/tty && read -r line </dev/tty && echo \"$line\"" :
428+
"cat >/dev/tty && read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty",
429+
NULL
430+
};
431+
struct child_process child = CHILD_PROCESS_INIT;
432+
static struct strbuf buffer = STRBUF_INIT;
433+
int prompt_len = strlen(prompt), len = -1, code;
434+
435+
strvec_pushv(&child.args, read_input);
436+
child.in = -1;
437+
child.out = -1;
438+
child.silent_exec_failure = 1;
439+
440+
if (start_command(&child))
441+
return NULL;
442+
443+
if (write_in_full(child.in, prompt, prompt_len) != prompt_len) {
444+
error("could not write to prompt script");
445+
close(child.in);
446+
goto ret;
447+
}
448+
close(child.in);
449+
450+
strbuf_reset(&buffer);
451+
len = strbuf_read(&buffer, child.out, 1024);
452+
if (len < 0) {
453+
error("could not read from prompt script");
454+
goto ret;
455+
}
456+
457+
strbuf_strip_suffix(&buffer, "\n");
458+
strbuf_strip_suffix(&buffer, "\r");
459+
460+
ret:
461+
close(child.out);
462+
code = finish_command(&child);
463+
if (code) {
464+
error("failed to execute prompt script (exit code %d)", code);
465+
return NULL;
466+
}
467+
468+
return len < 0 ? NULL : buffer.buf;
469+
}
470+
422471
#endif
423472

424473
#ifndef FORCE_TEXT
@@ -431,6 +480,15 @@ char *git_terminal_prompt(const char *prompt, int echo)
431480
int r;
432481
FILE *input_fh, *output_fh;
433482

483+
#ifdef GIT_WINDOWS_NATIVE
484+
485+
/* try shell_prompt first, fall back to CONIN/OUT if bash is missing */
486+
char *result = shell_prompt(prompt, echo);
487+
if (result)
488+
return result;
489+
490+
#endif
491+
434492
input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT);
435493
if (!input_fh)
436494
return NULL;

gpg-interface.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -972,12 +972,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
972972
struct child_process gpg = CHILD_PROCESS_INIT;
973973
int ret;
974974
size_t bottom;
975-
const char *cp;
976-
struct strbuf gpg_status = STRBUF_INIT;
977975

978976
strvec_pushl(&gpg.args,
979977
use_format->program,
980-
"--status-fd=2",
981978
"-bsau", signing_key,
982979
NULL);
983980

@@ -989,23 +986,11 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
989986
*/
990987
sigchain_push(SIGPIPE, SIG_IGN);
991988
ret = pipe_command(&gpg, buffer->buf, buffer->len,
992-
signature, 1024, &gpg_status, 0);
989+
signature, 1024, NULL, 0);
993990
sigchain_pop(SIGPIPE);
994991

995-
for (cp = gpg_status.buf;
996-
cp && (cp = strstr(cp, "[GNUPG:] SIG_CREATED "));
997-
cp++) {
998-
if (cp == gpg_status.buf || cp[-1] == '\n')
999-
break; /* found */
1000-
}
1001-
ret |= !cp;
1002-
if (ret) {
1003-
error(_("gpg failed to sign the data:\n%s"),
1004-
gpg_status.len ? gpg_status.buf : "(no gpg output)");
1005-
strbuf_release(&gpg_status);
1006-
return -1;
1007-
}
1008-
strbuf_release(&gpg_status);
992+
if (ret || signature->len == bottom)
993+
return error(_("gpg failed to sign the data"));
1009994

1010995
/* Strip CR from the line endings, in case we are on Windows. */
1011996
remove_cr_after(signature, bottom);

t/t7004-tag.sh

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,44 +1517,13 @@ test_expect_success GPG \
15171517
'test_config user.signingkey BobTheMouse &&
15181518
test_must_fail git tag -s -m tail tag-gpg-failure'
15191519

1520-
# try to produce invalid signature
1521-
test_expect_success GPG \
1522-
'git tag -s fails if gpg is misconfigured (bad signature format)' \
1523-
'test_config gpg.program echo &&
1524-
test_must_fail git tag -s -m tail tag-gpg-failure'
1525-
1526-
# try to produce invalid signature
1527-
test_expect_success GPG 'git verifies tag is valid with double signature' '
1528-
git tag -s -m tail tag-gpg-double-sig &&
1529-
git cat-file tag tag-gpg-double-sig >tag &&
1530-
othersigheader=$(test_oid othersigheader) &&
1531-
sed -ne "/^\$/q;p" tag >new-tag &&
1532-
cat <<-EOM >>new-tag &&
1533-
$othersigheader -----BEGIN PGP SIGNATURE-----
1534-
someinvaliddata
1535-
-----END PGP SIGNATURE-----
1536-
EOM
1537-
sed -e "1,/^tagger/d" tag >>new-tag &&
1538-
new_tag=$(git hash-object -t tag -w new-tag) &&
1539-
git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1540-
git verify-tag tag-gpg-double-sig &&
1541-
git fsck
1542-
'
1543-
15441520
# try to sign with bad user.signingkey
15451521
test_expect_success GPGSM \
15461522
'git tag -s fails if gpgsm is misconfigured (bad key)' \
15471523
'test_config user.signingkey BobTheMouse &&
15481524
test_config gpg.format x509 &&
15491525
test_must_fail git tag -s -m tail tag-gpg-failure'
15501526

1551-
# try to produce invalid signature
1552-
test_expect_success GPGSM \
1553-
'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1554-
'test_config gpg.x509.program echo &&
1555-
test_config gpg.format x509 &&
1556-
test_must_fail git tag -s -m tail tag-gpg-failure'
1557-
15581527
# try to verify without gpg:
15591528

15601529
rm -rf gpghome

0 commit comments

Comments
 (0)