Skip to content

Commit c9a2b24

Browse files
dschomjcheetham
authored andcommitted
Merge branch 'msys2'
2 parents 94008db + 9ce9965 commit c9a2b24

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
@@ -420,6 +420,55 @@ static int getchar_with_timeout(int timeout)
420420
return getchar();
421421
}
422422

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

425474
#ifndef FORCE_TEXT
@@ -432,6 +481,15 @@ char *git_terminal_prompt(const char *prompt, int echo)
432481
int r;
433482
FILE *input_fh, *output_fh;
434483

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

gpg-interface.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -977,12 +977,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
977977
struct child_process gpg = CHILD_PROCESS_INIT;
978978
int ret;
979979
size_t bottom;
980-
const char *cp;
981-
struct strbuf gpg_status = STRBUF_INIT;
982980

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

@@ -994,23 +991,11 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
994991
*/
995992
sigchain_push(SIGPIPE, SIG_IGN);
996993
ret = pipe_command(&gpg, buffer->buf, buffer->len,
997-
signature, 1024, &gpg_status, 0);
994+
signature, 1024, NULL, 0);
998995
sigchain_pop(SIGPIPE);
999996

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

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

t/t7004-tag.sh

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

1406-
# try to produce invalid signature
1407-
test_expect_success GPG \
1408-
'git tag -s fails if gpg is misconfigured (bad signature format)' \
1409-
'test_config gpg.program echo &&
1410-
test_must_fail git tag -s -m tail tag-gpg-failure'
1411-
1412-
# try to produce invalid signature
1413-
test_expect_success GPG 'git verifies tag is valid with double signature' '
1414-
git tag -s -m tail tag-gpg-double-sig &&
1415-
git cat-file tag tag-gpg-double-sig >tag &&
1416-
othersigheader=$(test_oid othersigheader) &&
1417-
sed -ne "/^\$/q;p" tag >new-tag &&
1418-
cat <<-EOM >>new-tag &&
1419-
$othersigheader -----BEGIN PGP SIGNATURE-----
1420-
someinvaliddata
1421-
-----END PGP SIGNATURE-----
1422-
EOM
1423-
sed -e "1,/^tagger/d" tag >>new-tag &&
1424-
new_tag=$(git hash-object -t tag -w new-tag) &&
1425-
git update-ref refs/tags/tag-gpg-double-sig $new_tag &&
1426-
git verify-tag tag-gpg-double-sig &&
1427-
git fsck
1428-
'
1429-
14301406
# try to sign with bad user.signingkey
14311407
test_expect_success GPGSM \
14321408
'git tag -s fails if gpgsm is misconfigured (bad key)' \
14331409
'test_config user.signingkey BobTheMouse &&
14341410
test_config gpg.format x509 &&
14351411
test_must_fail git tag -s -m tail tag-gpg-failure'
14361412

1437-
# try to produce invalid signature
1438-
test_expect_success GPGSM \
1439-
'git tag -s fails if gpgsm is misconfigured (bad signature format)' \
1440-
'test_config gpg.x509.program echo &&
1441-
test_config gpg.format x509 &&
1442-
test_must_fail git tag -s -m tail tag-gpg-failure'
1443-
14441413
# try to verify without gpg:
14451414

14461415
rm -rf gpghome

0 commit comments

Comments
 (0)