Skip to content

Commit 52c0aa9

Browse files
committed
Merge branch 'msys2'
2 parents c01da16 + 591a434 commit 52c0aa9

File tree

3 files changed

+61
-38
lines changed

3 files changed

+61
-38
lines changed

compat/terminal.c

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "git-compat-util.h"
1+
#include "cache.h"
22
#include "compat/terminal.h"
33
#include "sigchain.h"
44
#include "strbuf.h"
@@ -228,6 +228,55 @@ static int mingw_getchar(void)
228228
}
229229
#define getchar mingw_getchar
230230

231+
static char *shell_prompt(const char *prompt, int echo)
232+
{
233+
const char *read_input[] = {
234+
/* Note: call 'bash' explicitly, as 'read -s' is bash-specific */
235+
"bash", "-c", echo ?
236+
"cat >/dev/tty && read -r line </dev/tty && echo \"$line\"" :
237+
"cat >/dev/tty && read -r -s line </dev/tty && echo \"$line\" && echo >/dev/tty",
238+
NULL
239+
};
240+
struct child_process child = CHILD_PROCESS_INIT;
241+
static struct strbuf buffer = STRBUF_INIT;
242+
int prompt_len = strlen(prompt), len = -1, code;
243+
244+
strvec_pushv(&child.args, read_input);
245+
child.in = -1;
246+
child.out = -1;
247+
child.silent_exec_failure = 1;
248+
249+
if (start_command(&child))
250+
return NULL;
251+
252+
if (write_in_full(child.in, prompt, prompt_len) != prompt_len) {
253+
error("could not write to prompt script");
254+
close(child.in);
255+
goto ret;
256+
}
257+
close(child.in);
258+
259+
strbuf_reset(&buffer);
260+
len = strbuf_read(&buffer, child.out, 1024);
261+
if (len < 0) {
262+
error("could not read from prompt script");
263+
goto ret;
264+
}
265+
266+
strbuf_strip_suffix(&buffer, "\n");
267+
strbuf_strip_suffix(&buffer, "\r");
268+
269+
ret:
270+
close(child.out);
271+
code = finish_command(&child);
272+
if (code) {
273+
error("failed to execute prompt script (exit code %d)", code);
274+
return NULL;
275+
}
276+
277+
return len < 0 ? NULL : buffer.buf;
278+
}
279+
231280
#endif
232281

233282
#ifndef FORCE_TEXT
@@ -240,6 +289,15 @@ char *git_terminal_prompt(const char *prompt, int echo)
240289
int r;
241290
FILE *input_fh, *output_fh;
242291

292+
#ifdef GIT_WINDOWS_NATIVE
293+
294+
/* try shell_prompt first, fall back to CONIN/OUT if bash is missing */
295+
char *result = shell_prompt(prompt, echo);
296+
if (result)
297+
return result;
298+
299+
#endif
300+
243301
input_fh = fopen(INPUT_PATH, "r" FORCE_TEXT);
244302
if (!input_fh)
245303
return NULL;

gpg-interface.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -920,11 +920,9 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
920920
struct child_process gpg = CHILD_PROCESS_INIT;
921921
int ret;
922922
size_t bottom;
923-
struct strbuf gpg_status = STRBUF_INIT;
924923

925924
strvec_pushl(&gpg.args,
926925
use_format->program,
927-
"--status-fd=2",
928926
"-bsau", signing_key,
929927
NULL);
930928

@@ -936,12 +934,10 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
936934
*/
937935
sigchain_push(SIGPIPE, SIG_IGN);
938936
ret = pipe_command(&gpg, buffer->buf, buffer->len,
939-
signature, 1024, &gpg_status, 0);
937+
signature, 1024, NULL, 0);
940938
sigchain_pop(SIGPIPE);
941939

942-
ret |= !strstr(gpg_status.buf, "\n[GNUPG:] SIG_CREATED ");
943-
strbuf_release(&gpg_status);
944-
if (ret)
940+
if (ret || signature->len == bottom)
945941
return error(_("gpg failed to sign the data"));
946942

947943
/* 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)