OSDN Git Service

Add Amend Last Commit Option
authorFrank Li <lznuaa@gmail.com>
Fri, 30 Jan 2009 08:11:25 +0000 (16:11 +0800)
committerFrank Li <lznuaa@gmail.com>
Fri, 30 Jan 2009 08:22:47 +0000 (16:22 +0800)
Simiplfy implement. It doesn't unstage committed file like git gui.

Signed-off-by: Frank Li <lznuaa@gmail.com>
src/Resources/TortoiseProcENG.rc
src/TortoiseProc/CommitDlg.cpp
src/TortoiseProc/CommitDlg.h
src/TortoiseProc/resource.h

index 3da30e7..45a016e 100644 (file)
Binary files a/src/Resources/TortoiseProcENG.rc and b/src/Resources/TortoiseProcENG.rc differ
index c99f282..9428018 100644 (file)
@@ -76,6 +76,7 @@ void CCommitDlg::DoDataExchange(CDataExchange* pDX)
        DDX_Check(pDX, IDC_KEEPLOCK, m_bKeepLocks);\r
        DDX_Control(pDX, IDC_SPLITTER, m_wndSplitter);\r
        DDX_Check(pDX, IDC_KEEPLISTS, m_bKeepChangeList);\r
+       DDX_Check(pDX,IDC_COMMIT_AMEND,m_bCommitAmend);\r
 }\r
 \r
 BEGIN_MESSAGE_MAP(CCommitDlg, CResizableStandAloneDialog)\r
@@ -123,7 +124,7 @@ BOOL CCommitDlg::OnInitDialog()
        m_ListCtrl.EnableFileDrop();\r
        m_ListCtrl.SetBackgroundImage(IDI_COMMIT_BKG);\r
        \r
-       this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);\r
+       //this->DialogEnableWindow(IDC_COMMIT_AMEND,FALSE);\r
 //     m_ProjectProperties.ReadPropsPathList(m_pathList);\r
        m_cLogMessage.Init(m_ProjectProperties);\r
        m_cLogMessage.SetFont((CString)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));\r
@@ -133,6 +134,7 @@ BOOL CCommitDlg::OnInitDialog()
 \r
        m_tooltips.Create(this);\r
        m_tooltips.AddTool(IDC_EXTERNALWARNING, IDS_COMMITDLG_EXTERNALS);\r
+       m_tooltips.AddTool(IDC_COMMIT_AMEND,IDS_COMMIT_AMEND_TT);\r
 //     m_tooltips.AddTool(IDC_HISTORY, IDS_COMMITDLG_HISTORY_TT);\r
        \r
        m_SelectAll.SetCheck(BST_INDETERMINATE);\r
@@ -279,6 +281,9 @@ BOOL CCommitDlg::OnInitDialog()
        }\r
        err = FALSE;\r
 \r
+       this->UpdateData(TRUE);\r
+       this->m_bCommitAmend=FALSE;\r
+       this->UpdateData(FALSE);\r
 \r
        return FALSE;  // return TRUE unless you set the focus to a control\r
        // EXCEPTION: OCX Property Pages should return FALSE\r
@@ -301,6 +306,8 @@ void CCommitDlg::OnOK()
                        InterlockedExchange(&m_bThreadRunning, FALSE);\r
                }\r
        }\r
+       this->UpdateData();\r
+\r
        CString id;\r
        GetDlgItemText(IDC_BUGID, id);\r
        if (!m_ProjectProperties.CheckBugID(id))\r
@@ -440,7 +447,7 @@ void CCommitDlg::OnOK()
        //}\r
 \r
        //if(checkedfiles.GetLength()>0)\r
-       if(nchecked)\r
+       if(nchecked||m_bCommitAmend)\r
        {\r
        //      cmd.Format(_T("git.exe update-index -- %s"),checkedfiles);\r
        //      g_Git.Run(cmd,&out);\r
@@ -453,7 +460,12 @@ void CCommitDlg::OnOK()
                file.Close();\r
        \r
                out =_T("");\r
-               cmd.Format(_T("git.exe commit -F \"%s\""), tempfile);\r
+               CString amend;\r
+               if(this->m_bCommitAmend)\r
+               {\r
+                       amend=_T("--amend");\r
+               }\r
+               cmd.Format(_T("git.exe commit %s -F \"%s\""),amend, tempfile);\r
                g_Git.Run(cmd,&out,CP_OEMCP);\r
        \r
                CFile::Remove(tempfile);\r
@@ -1458,4 +1470,26 @@ void CCommitDlg::OnStnClickedCommitlabel()
 void CCommitDlg::OnBnClickedCommitAmend()\r
 {\r
     // TODO: Add your control notification handler code here\r
+       this->UpdateData();\r
+       if(this->m_bCommitAmend && this->m_AmendStr.IsEmpty())\r
+       {\r
+               GitRev rev;\r
+               BYTE_VECTOR vector;\r
+               g_Git.GetLog(vector,CString(_T("HEAD")),NULL,1);\r
+               rev.ParserFromLog(vector);\r
+               m_AmendStr=rev.m_Subject+_T("\n\n")+rev.m_Body;\r
+       }\r
+\r
+       if(this->m_bCommitAmend)\r
+       {\r
+               this->m_NoAmendStr=this->m_cLogMessage.GetText();\r
+               m_cLogMessage.SetText(m_AmendStr);\r
+\r
+       }else\r
+       {\r
+               this->m_AmendStr=this->m_cLogMessage.GetText();\r
+               m_cLogMessage.SetText(m_NoAmendStr);\r
+\r
+       }\r
+\r
 }\r
index c3c7a8f..be38eea 100644 (file)
@@ -107,9 +107,12 @@ public:
        CString                         m_sBugID;\r
        CString                         m_sChangeList;\r
        BOOL                            m_bKeepChangeList;\r
+       BOOL                            m_bCommitAmend;\r
        INT_PTR                         m_itemsCount;\r
        bool                            m_bSelectFilesForCommit;\r
 //     CComPtr<IBugTraqProvider> m_BugTraqProvider;\r
+       CString                         m_NoAmendStr;\r
+       CString                         m_AmendStr;\r
 \r
 private:\r
        CWinThread*                     m_pThread;\r
index cf2186c..4c4fd9e 100644 (file)
Binary files a/src/TortoiseProc/resource.h and b/src/TortoiseProc/resource.h differ