Skip to content

Commit 2f3e89e

Browse files
committed
Merge branch 'msys2'
2 parents baefe0a + 5376f63 commit 2f3e89e

File tree

3 files changed

+60
-44
lines changed

3 files changed

+60
-44
lines changed

compat/terminal.c

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

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

423472
#ifndef FORCE_TEXT
@@ -430,6 +479,15 @@ char *git_terminal_prompt(const char *prompt, int echo)
430479
int r;
431480
FILE *input_fh, *output_fh;
432481

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

gpg-interface.c

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -950,12 +950,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
950950
struct child_process gpg = CHILD_PROCESS_INIT;
951951
int ret;
952952
size_t bottom;
953-
const char *cp;
954-
struct strbuf gpg_status = STRBUF_INIT;
955953

956954
strvec_pushl(&gpg.args,
957955
use_format->program,
958-
"--status-fd=2",
959956
"-bsau", signing_key,
960957
NULL);
961958

@@ -967,18 +964,10 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
967964
*/
968965
sigchain_push(SIGPIPE, SIG_IGN);
969966
ret = pipe_command(&gpg, buffer->buf, buffer->len,
970-
signature, 1024, &gpg_status, 0);
967+
signature, 1024, NULL, 0);
971968
sigchain_pop(SIGPIPE);
972969

973-
for (cp = gpg_status.buf;
974-
cp && (cp = strstr(cp, "[GNUPG:] SIG_CREATED "));
975-
cp++) {
976-
if (cp == gpg_status.buf || cp[-1] == '\n')
977-
break; /* found */
978-
}
979-
ret |= !cp;
980-
strbuf_release(&gpg_status);
981-
if (ret)
970+
if (ret || signature->len == bottom)
982971
return error(_("gpg failed to sign the data"));
983972

984973
/* Strip CR from the line endings, in case we are on Windows. */

t/t7004-tag.sh

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

1378-
# try to produce invalid signature
1379-
test_expect_success GPG \
1380-
'git tag -s fails if gpg is misconfigured (bad signature format)' \
1381-
'test_config gpg.program echo &&
1382-
test_must_fail git tag -s -m tail tag-gpg-failure'
1383-
1384-
# try to produce invalid signature
1385-
test_expect_success GPG 'git verifies tag is valid with double signature' '
1386-
git tag -s -m tail tag-gpg-double-sig &&
1387-
git cat-file tag tag-gpg-double-sig >tag &&
1388-
othersigheader=$(test_oid othersigheader) &&
1389-
sed -ne "/^\$/q;p" tag >new-tag &&
1390-
cat <<-EOM >>new-tag &&
1391-
$othersigheader -----BEGIN PGP SIGNATURE-----
1392-
someinvaliddata
1393-
-----END PGP SIGNATURE-----
1394-
EOM
1395-
sed -e "1,/^tagger/d" tag >>new-tag &&
1396-
new_tag=$(git hash-object -t tag -w new-tag) &&
1397-
git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1398-
git verify-tag tag-gpg-double-sig &&
1399-
git fsck
1400-
'
1401-
14021378
# try to sign with bad user.signingkey
14031379
test_expect_success GPGSM \
14041380
'git tag -s fails if gpgsm is misconfigured (bad key)' \
14051381
'test_config user.signingkey BobTheMouse &&
14061382
test_config gpg.format x509 &&
14071383
test_must_fail git tag -s -m tail tag-gpg-failure'
14081384

1409-
# try to produce invalid signature
1410-
test_expect_success GPGSM \
1411-
'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1412-
'test_config gpg.x509.program echo &&
1413-
test_config gpg.format x509 &&
1414-
test_must_fail git tag -s -m tail tag-gpg-failure'
1415-
14161385
# try to verify without gpg:
14171386

14181387
rm -rf gpghome

0 commit comments

Comments
 (0)