@matheusbsbs / matheus-bagliano / commits / 68b2859389
Fork 0

git-p4: fix key error for p4 problem

Some p4 failures result in an error, but the info['code'] is not set. These include a bad p4 executable, or a core dump from p4, and other odd internal errors where p4 fails to generate proper marshaled output. Make sure the info key exists before using it to avoid a python traceback. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Feb 19, 2011 at 08:17 UTC 68b28593899d528d4b59e7eb07cc37b85012376a
2 files changed +17 -1
contrib/fast-import/git-p4
+4 -1
@@ -1440,10 +1440,13 @@ class P4Sync(Command):
1440 % (p, revision)
1441 for p in self.depotPaths])):
1442
1443 - if info['code'] == 'error':
1443 + if 'code' in info and info['code'] == 'error':
1444 sys.stderr.write("p4 returned an error: %s\n"
1445 % info['data'])
1446 sys.exit(1)
1447 + if 'p4ExitCode' in info:
1448 + sys.stderr.write("p4 exitcode: %s\n" % info['p4ExitCode'])
1449 + sys.exit(1)
1450
1451
1452 change = int(info["change"])
t/t9800-git-p4.sh
+13
@@ -45,6 +45,19 @@ test_expect_success 'basic git-p4 clone' '
45 rm -rf "$git" && mkdir "$git"
46 '
47
48 +test_expect_success 'exit when p4 fails to produce marshaled output' '
49 + badp4dir="$TRASH_DIRECTORY/badp4dir" &&
50 + mkdir -p "$badp4dir" &&
51 + cat >"$badp4dir"/p4 <<-EOF &&
52 + #!$SHELL_PATH
53 + exit 1
54 + EOF
55 + chmod 755 "$badp4dir"/p4 &&
56 + PATH="$badp4dir:$PATH" "$GITP4" clone --dest="$git" //depot >errs 2>&1 ; retval=$? &&
57 + test $retval -eq 1 &&
58 + test_must_fail grep -q Traceback errs
59 +'
60 +
61 test_expect_success 'shutdown' '
62 pid=`pgrep -f p4d` &&
63 test -n "$pid" &&