Skip to content

Commit 5a8b0b4

Browse files
committed
Merge branch 'msys2'
2 parents 38f18e6 + 5fa3a70 commit 5a8b0b4

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
@@ -978,12 +978,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
978978
struct child_process gpg = CHILD_PROCESS_INIT;
979979
int ret;
980980
size_t bottom;
981-
const char *cp;
982-
struct strbuf gpg_status = STRBUF_INIT;
983981

984982
strvec_pushl(&gpg.args,
985983
use_format->program,
986-
"--status-fd=2",
987984
"-bsau", signing_key,
988985
NULL);
989986

@@ -995,23 +992,11 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
995992
*/
996993
sigchain_push(SIGPIPE, SIG_IGN);
997994
ret = pipe_command(&gpg, buffer->buf, buffer->len,
998-
signature, 1024, &gpg_status, 0);
995+
signature, 1024, NULL, 0);
999996
sigchain_pop(SIGPIPE);
1000997

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

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

t/t7004-tag.sh

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,44 +1465,13 @@ test_expect_success GPG 'git tag -s fails if gpg is misconfigured (bad key)' '
14651465
test_must_fail git tag -s -m tail tag-gpg-failure
14661466
'
14671467

1468-
# try to produce invalid signature
1469-
test_expect_success GPG 'git tag -s fails if gpg is misconfigured (bad signature format)' '
1470-
test_config gpg.program echo &&
1471-
test_must_fail git tag -s -m tail tag-gpg-failure
1472-
'
1473-
1474-
# try to produce invalid signature
1475-
test_expect_success GPG 'git verifies tag is valid with double signature' '
1476-
git tag -s -m tail tag-gpg-double-sig &&
1477-
git cat-file tag tag-gpg-double-sig >tag &&
1478-
othersigheader=$(test_oid othersigheader) &&
1479-
sed -ne "/^\$/q;p" tag >new-tag &&
1480-
cat <<-EOM >>new-tag &&
1481-
$othersigheader -----BEGIN PGP SIGNATURE-----
1482-
someinvaliddata
1483-
-----END PGP SIGNATURE-----
1484-
EOM
1485-
sed -e "1,/^tagger/d" tag >>new-tag &&
1486-
new_tag=$(git hash-object -t tag -w new-tag) &&
1487-
git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1488-
git verify-tag tag-gpg-double-sig &&
1489-
git fsck
1490-
'
1491-
14921468
# try to sign with bad user.signingkey
14931469
test_expect_success GPGSM 'git tag -s fails if gpgsm is misconfigured (bad key)' '
14941470
test_config user.signingkey BobTheMouse &&
14951471
test_config gpg.format x509 &&
14961472
test_must_fail git tag -s -m tail tag-gpg-failure
14971473
'
14981474

1499-
# try to produce invalid signature
1500-
test_expect_success GPGSM 'git tag -s fails if gpgsm is misconfigured (bad signature format)' '
1501-
test_config gpg.x509.program echo &&
1502-
test_config gpg.format x509 &&
1503-
test_must_fail git tag -s -m tail tag-gpg-failure
1504-
'
1505-
15061475
# try to verify without gpg:
15071476

15081477
test_expect_success GPG 'verify signed tag fails when public key is not present' '

0 commit comments

Comments
 (0)