Skip to content

Commit 5ea74f4

Browse files
dschoGit for Windows Build Agent
authored and
Git for Windows Build Agent
committed
Merge branch 'msys2'
2 parents 9a33982 + 44c1281 commit 5ea74f4

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
@@ -980,12 +980,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
980980
struct child_process gpg = CHILD_PROCESS_INIT;
981981
int ret;
982982
size_t bottom;
983-
const char *cp;
984-
struct strbuf gpg_status = STRBUF_INIT;
985983

986984
strvec_pushl(&gpg.args,
987985
use_format->program,
988-
"--status-fd=2",
989986
"-bsau", signing_key,
990987
NULL);
991988

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

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

10181003
/* Strip CR from the line endings, in case we are on Windows. */
10191004
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)