Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Remember git commit message #158

Closed
Snegovikufa opened this Issue · 3 comments

2 participants

@Snegovikufa

If you open git-gui, write commit message, close application and reopen again, you'll see your message was remembered. Git-gui stores commit message in .git/GITGUI_MSG file.
Can you implement something like this ?

@davvid
Owner

This would be a nice addition. The code already goes through the trouble of creating a temporary file for passing off to git commit. Having it live in a persistent place that the editor reads from could end up making it simpler.

We already have code that knows to read .git/MERGE_MSG. We would need to rework that to also look for .git/GIT_COLA_MSG, write its contents there on shutdown, and empty the file when git commit succeeds.

@Snegovikufa

I've implemented patch for saving/loading commit messages, but have no enough time to make it look shiny :smile:

diff --git a/cola/gitcmds.py b/cola/gitcmds.py
index 1e60b77..8df07d7 100644
--- a/cola/gitcmds.py
+++ b/cola/gitcmds.py
@@ -623,6 +623,15 @@ def rev_list_range(start, end):
     return parse_rev_list(raw_revs)


+def commit_message_path():
+    """Return the path to .git/COMMIT_MSG"""
+    path = git.git_path("COMMIT_MSG")
+    if os.path.exists(path):
+        return path
+
+    return None
+
+
 def merge_message_path():
     """Return the path to .git/MERGE_MSG or .git/SQUASH_MSG."""
     for basename in ('MERGE_MSG', 'SQUASH_MSG'):
diff --git a/cola/main/model.py b/cola/main/model.py
index 48345fd..71fbf23 100644
--- a/cola/main/model.py
+++ b/cola/main/model.py
@@ -125,6 +125,10 @@ class MainModel(Observable):
         self.commitmsg = msg
         self.notify_observers(self.message_commit_message_changed, msg)

+        path = git.git.git_path("COMMIT_MSG")
+        with open(path, "w") as f:
+            f.write(self.commitmsg)
+
     def set_diff_text(self, txt):
         self.diff_text = txt
         self.notify_observers(self.message_diff_text_changed, txt)
diff --git a/cola/main/view.py b/cola/main/view.py
index 97659f3..7bce42b 100644
--- a/cola/main/view.py
+++ b/cola/main/view.py
@@ -476,6 +476,11 @@ class MainView(MainWindow):
         s = settings.Settings()
         s.add_recent(core.decode(os.getcwd()))
         qtutils.save_state(self, handler=s)
+        commit_msg = self.commitmsgeditor.commit_message(self)
+        commit_msg_path = git.git_path("COMMIT_MSG")
+        with open(commit_msg_path, "w") as f :
+            f.write(commit_msg)
+
         MainWindow.closeEvent(self, event)

     def build_recent_menu(self):
@@ -688,3 +693,4 @@ class MainView(MainWindow):
             display = ('<span style="color: grey;">%s</span>' % display)

         self.position_label.setText(display)
+
diff --git a/cola/widgets/commitmsg.py b/cola/widgets/commitmsg.py
index 6b42c80..a687bbf 100644
--- a/cola/widgets/commitmsg.py
+++ b/cola/widgets/commitmsg.py
@@ -5,6 +5,7 @@ from PyQt4.QtCore import SIGNAL

 import cola
 from cola import cmds
+from cola import core
 from cola import gitcmds
 from cola import utils
 from cola.cmds import Interaction
@@ -26,6 +27,7 @@ from cola.dag.model import RepoReader
 from cola.widgets.selectcommits import select_commits
 from cola.widgets.text import HintedLineEdit
 from cola.widgets.text import HintedTextEdit
+from cola.gitcmds import commit_message_path


 class CommitMessageEditor(QtGui.QWidget):
@@ -51,6 +53,19 @@ class CommitMessageEditor(QtGui.QWidget):
                                         cmds.Commit.SHORTCUT)
         self.commit_action.setToolTip(N_('Commit staged changes'))

+        # Loading message
+        summary_msg = ""
+        descr_msg = ""
+        commit_msg_path = commit_message_path()
+        if commit_msg_path:
+            commit_msg_path = core.decode(commit_msg_path)
+            with open(commit_msg_path) as f:
+                message = f.read()
+                all_messages = message.split('\n')
+                if len(all_messages) >= 1:
+                    summary_msg = all_messages[0]
+                    descr_msg = "\n".join(all_messages[2:])
+
         # Widgets
         self.summary = CommitSummaryLineEdit()
         self.summary.extra_actions.append(self.signoff_action)
@@ -150,6 +165,9 @@ class CommitMessageEditor(QtGui.QWidget):
         self.summary.enable_hint(True)
         self.description.enable_hint(True)

+        self.summary.set_value(summary_msg)
+        self.description.set_value(descr_msg)
+
         self.commit_button.setEnabled(False)
         self.commit_action.setEnabled(False)

@Snegovikufa Snegovikufa referenced this issue from a commit
@Snegovikufa Snegovikufa #158: Implement loading/saving commit message
Make app to save commit message to .GIT_COLA_MSG when app exits and
load commit message from file when opening the same repository again
f6be2d2
@davvid
Owner

This feature was implemented in pull requested #175

@davvid davvid closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.