Ensure that the commit message is Windows formated (CRLF) before invoking the editor.
[gitweb.git] / contrib / fast-import / git-p4
index 50d92c0f428bc9f7924fbb65d5e40ea442b1dad8..fc4e7d26f061621ac424a92b15cfc9132b76247b 100755 (executable)
@@ -276,6 +276,8 @@ class P4Submit(Command):
         self.origin = ""
         self.directSubmit = False
         self.trustMeLikeAFool = False
+        self.verbose = False
+        self.isWindows = (platform.system() == "Windows")
 
         self.logSubstitutions = {}
         self.logSubstitutions["<enter description here>"] = "%log%"
@@ -397,6 +399,8 @@ class P4Submit(Command):
         if not self.directSubmit:
             logMessage = extractLogMessageFromGitCommit(id)
             logMessage = logMessage.replace("\n", "\n\t")
+            if self.isWindows:
+                logMessage = logMessage.replace("\n", "\r\n")
             logMessage = logMessage.strip()
 
         template = read_pipe("p4 change -o")
@@ -443,6 +447,8 @@ class P4Submit(Command):
                     tmpFile.close()
                     os.remove(fileName)
                     submitTemplate = message[:message.index(separatorLine)]
+                    if self.isWindows:
+                        submitTemplate = submitTemplate.replace("\r\n", "\n")
 
             if response == "y" or response == "yes":
                if self.dryRun:
@@ -478,9 +484,6 @@ class P4Submit(Command):
                    % (fileName, fileName))
 
     def run(self, args):
-        # make gitdir absolute so we can cd out into the perforce checkout
-        os.environ["GIT_DIR"] = gitdir
-
         if len(args) == 0:
             self.master = currentGitBranch()
             if len(self.master) == 0 or not gitBranchExists("refs/heads/%s" % self.master):
@@ -496,7 +499,7 @@ class P4Submit(Command):
             settings = extractSettingsGitLog(extractLogMessageFromGitCommit("p4"))
         if len(depotPath) == 0 and gitBranchExists("origin"):
             settings = extractSettingsGitLog(extractLogMessageFromGitCommit("origin"))
-        depotPaths = settings['depot-paths']
+        depotPath = settings['depot-paths'][0]
 
         if len(depotPath) == 0:
             print "Internal error: cannot locate perforce depot path from existing branches"