git-p4: show Perforce error to the user

During "git p4 clone" if p4 process returns an error from the server, it will store the message in the 'err' variable. Then it will send a text command "die-now" to git-fast-import. However, git-fast-import raises an exception: "fatal: Unsupported command: die-now" and err is never displayed. This patch ensures that err is shown to the end user. Signed-off-by: Fahad Alrashed <fahad@keylock.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Fahad Alrashed committed May 8, 2024 at 22:11 UTC 55702c543ea39230847dfc635ea1b604d66d9b83
1 file changed +13 -11
git-p4.py
+13 -11
@@ -3253,17 +3253,19 @@ class P4Sync(Command, P4UserMap):
3253 if self.stream_have_file_info:
3254 if "depotFile" in self.stream_file:
3255 f = self.stream_file["depotFile"]
3256 - # force a failure in fast-import, else an empty
3257 - # commit will be made
3258 - self.gitStream.write("\n")
3259 - self.gitStream.write("die-now\n")
3260 - self.gitStream.close()
3261 - # ignore errors, but make sure it exits first
3262 - self.importProcess.wait()
3263 - if f:
3264 - die("Error from p4 print for %s: %s" % (f, err))
3265 - else:
3266 - die("Error from p4 print: %s" % err)
3256 + try:
3257 + # force a failure in fast-import, else an empty
3258 + # commit will be made
3259 + self.gitStream.write("\n")
3260 + self.gitStream.write("die-now\n")
3261 + self.gitStream.close()
3262 + # ignore errors, but make sure it exits first
3263 + self.importProcess.wait()
3264 + finally:
3265 + if f:
3266 + die("Error from p4 print for %s: %s" % (f, err))
3267 + else:
3268 + die("Error from p4 print: %s" % err)
3269
3270 if 'depotFile' in marshalled and self.stream_have_file_info:
3271 # start of a new file - output the old one first