- fileName = "submit.txt"
- file = open(fileName, "w+")
- file.write(prepareLogMessage(template, logMessage))
- file.close()
- print "Perforce submit template written as %s. Please review/edit and then use p4 submit -i < %s to submit directly!" % (fileName, fileName)
+
+ if interactive:
+ submitTemplate = prepareLogMessage(template, logMessage)
+ diff = os.popen("p4 diff -du ...").read()
+
+ for newFile in filesToAdd:
+ diff += "==== new file ====\n"
+ diff += "--- /dev/null\n"
+ diff += "+++ %s\n" % newFile
+ f = open(newFile, "r")
+ for line in f.readlines():
+ diff += "+" + line
+ f.close()
+
+ pipe = os.popen("less", "w")
+ pipe.write(submitTemplate + diff)
+ pipe.close()
+
+ response = "e"
+ while response == "e":
+ response = raw_input("Do you want to submit this change (y/e/n)? ")
+ if response == "e":
+ [handle, fileName] = tempfile.mkstemp()
+ tmpFile = os.fdopen(handle, "w+")
+ tmpFile.write(submitTemplate)
+ tmpFile.close()
+ editor = os.environ.get("EDITOR", "vi")
+ system(editor + " " + fileName)
+ tmpFile = open(fileName, "r")
+ submitTemplate = tmpFile.read()
+ tmpFile.close()
+ os.remove(fileName)
+
+ if response == "y" or response == "yes":
+ if dryRun:
+ print submitTemplate
+ raw_input("Press return to continue...")
+ else:
+ pipe = os.popen("p4 submit -i", "w")
+ pipe.write(submitTemplate)
+ pipe.close()
+ else:
+ print "Not submitting!"
+ interactive = False
+ else:
+ fileName = "submit.txt"
+ file = open(fileName, "w+")
+ file.write(prepareLogMessage(template, logMessage))
+ file.close()
+ print "Perforce submit template written as %s. Please review/edit and then use p4 submit -i < %s to submit directly!" % (fileName, fileName)