OSDN Git Service

BrowseRef: Use CMessageBox to display confirm message.
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / BrowseRefsDlg.cpp
index 159eaa9..09c3fc1 100644 (file)
@@ -10,7 +10,7 @@
 #include "Settings\SettingGitRemote.h"\r
 #include "SinglePropSheetDlg.h"\r
 #include "ConfirmDelRefDlg.h"\r
-\r
+#include "MessageBox.h"\r
 \r
 // CBrowseRefsDlg dialog\r
 \r
@@ -313,19 +313,99 @@ void CBrowseRefsDlg::OnContextMenu_ListRefLeafs(CPoint point)
                break;\r
        case eCmd_DeleteBranch:\r
                {\r
-                       CConfirmDelRefDlg(selectedTrees[0]->GetRefName(),this).DoModal();\r
+                       if(ConfirmDeleteRef(selectedTrees[0]->GetRefName()))\r
+                               DoDeleteRef(selectedTrees[0]->GetRefName(), true);\r
                        Refresh();\r
                }\r
                break;\r
        case eCmd_DeleteTag:\r
                {\r
-                       CConfirmDelRefDlg(selectedTrees[0]->GetRefName(),this).DoModal();\r
+                       if(ConfirmDeleteRef(selectedTrees[0]->GetRefName()))\r
+                               DoDeleteRef(selectedTrees[0]->GetRefName(), true);\r
                        Refresh();\r
                }\r
                break;\r
        }\r
 }\r
 \r
+bool CBrowseRefsDlg::ConfirmDeleteRef(CString completeRefName)\r
+{\r
+       CString csMessage;\r
+       CString csTitle;\r
+\r
+       UINT mbIcon=MB_ICONQUESTION;\r
+       csMessage=L"Are you sure you want to delete the ";\r
+       if(wcsncmp(completeRefName,L"refs/heads",10)==0)\r
+       {\r
+               CString branchToDelete = completeRefName.Mid(11);\r
+               csTitle.Format(L"Confirm deletion of branch %s", branchToDelete);\r
+               csMessage += "branch:\r\n\r\n<b>";\r
+               csMessage += branchToDelete;\r
+               csMessage += "</b>";\r
+\r
+               //Check if branch is fully merged in HEAD\r
+               CString branchHash = g_Git.GetHash(completeRefName);\r
+               CString commonAncestor;\r
+               CString cmd;\r
+               cmd.Format(L"git.exe merge-base HEAD %s",completeRefName);\r
+               g_Git.Run(cmd,&commonAncestor,CP_UTF8);\r
+\r
+               branchHash=branchHash.Left(40);\r
+               commonAncestor=commonAncestor.Left(40);\r
+               \r
+               if(commonAncestor != branchHash)\r
+               {\r
+                       csMessage += L"\r\n\r\n<b>Warning:\r\nThis branch is not fully merged into HEAD.</b>";\r
+                       mbIcon=MB_ICONWARNING;\r
+               }\r
+       }\r
+       else if(wcsncmp(completeRefName,L"refs/tags",9)==0)\r
+       {\r
+               CString tagToDelete = completeRefName.Mid(10);\r
+               csTitle.Format(L"Confirm deletion of tag %s", tagToDelete);\r
+               csMessage += "tag:\r\n\r\n<b>";\r
+               csMessage += tagToDelete;\r
+               csMessage += "</b>";\r
+       }\r
+\r
+       return CMessageBox::Show(m_hWnd,csMessage,csTitle,MB_YESNO|mbIcon)==IDYES;\r
+\r
+}\r
+\r
+\r
+bool CBrowseRefsDlg::DoDeleteRef(CString completeRefName, bool bForce)\r
+{\r
+       if(wcsncmp(completeRefName,L"refs/heads",10)==0)\r
+       {\r
+               CString branchToDelete = completeRefName.Mid(11);\r
+               CString cmd;\r
+               cmd.Format(L"git.exe branch -%c %s",bForce?L'D':L'd',branchToDelete);\r
+               CString resultDummy;\r
+               if(g_Git.Run(cmd,&resultDummy,CP_UTF8)!=0)\r
+               {\r
+                       CString errorMsg;\r
+                       errorMsg.Format(L"Could not delete branch %s. Message from git:\r\n\r\n%s",branchToDelete,resultDummy);\r
+                       CMessageBox::Show(m_hWnd,errorMsg,L"Error deleting branch",MB_OK|MB_ICONERROR);\r
+                       return false;\r
+               }\r
+       }\r
+       else if(wcsncmp(completeRefName,L"refs/tags",9)==0)\r
+       {\r
+               CString tagToDelete = completeRefName.Mid(10);\r
+               CString cmd;\r
+               cmd.Format(L"git.exe tag -d %s",tagToDelete);\r
+               CString resultDummy;\r
+               if(g_Git.Run(cmd,&resultDummy,CP_UTF8)!=0)\r
+               {\r
+                       CString errorMsg;\r
+                       errorMsg.Format(L"Could not delete tag %s. Message from git:\r\n\r\n%s",tagToDelete,resultDummy);\r
+                       CMessageBox::Show(m_hWnd,errorMsg,L"Error deleting tag",MB_OK|MB_ICONERROR);\r
+                       return false;\r
+               }\r
+       }\r
+       return true;\r
+}\r
+\r
 void CBrowseRefsDlg::OnContextMenu(CWnd* pWndFrom, CPoint point)\r
 {\r
        if(pWndFrom==&m_RefTreeCtrl)       OnContextMenu_RefTreeCtrl(point);\r