OSDN Git Service

BrowseRefs: Added option to delete remote branch original
authorJohan 't Hart <johanthart@gmail.com>
Tue, 9 Jun 2009 21:10:34 +0000 (23:10 +0200)
committerJohan 't Hart <johanthart@gmail.com>
Tue, 9 Jun 2009 21:10:34 +0000 (23:10 +0200)
src/TortoiseProc/BrowseRefsDlg.cpp
src/TortoiseProc/BrowseRefsDlg.h

index f8509c0..278853b 100644 (file)
@@ -391,14 +391,24 @@ bool CBrowseRefsDlg::ConfirmDeleteRef(CString completeRefName)
        CString csTitle;\r
 \r
        UINT mbIcon=MB_ICONQUESTION;\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 = L"Are you sure you want to delete the ";\r
+\r
+       bool bIsRemoteBranch = false;\r
+       bool bIsBranch = false;\r
+       if              (wcsncmp(completeRefName, L"refs/remotes",12)==0)       {bIsBranch = true; bIsRemoteBranch = true;}\r
+       else if (wcsncmp(completeRefName, L"refs/heads",10)==0)         {bIsBranch = true;}\r
+\r
+       if(bIsBranch)\r
+       {\r
+               CString branchToDelete = completeRefName.Mid(bIsRemoteBranch ? 13 : 11);\r
+               csTitle.Format(L"Confirm deletion of %sbranch %s", \r
+                       bIsRemoteBranch? L"remote ": L"", \r
+                       branchToDelete);\r
+               if(bIsRemoteBranch)\r
+                       csMessage += L"<ct=0x0000FF><i>remote</i></ct> "; \r
+               csMessage += L"branch:\r\n\r\n<b>";\r
                csMessage += branchToDelete;\r
                csMessage += branchToDelete;\r
-               csMessage += "</b>";\r
+               csMessage += L"</b>";\r
 \r
                //Check if branch is fully merged in HEAD\r
                CString branchHash = g_Git.GetHash(completeRefName);\r
 \r
                //Check if branch is fully merged in HEAD\r
                CString branchHash = g_Git.GetHash(completeRefName);\r
@@ -413,7 +423,12 @@ bool CBrowseRefsDlg::ConfirmDeleteRef(CString completeRefName)
                if(commonAncestor != branchHash)\r
                {\r
                        csMessage += L"\r\n\r\n<b>Warning:\r\nThis branch is not fully merged into HEAD.</b>";\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
+                       mbIcon = MB_ICONWARNING;\r
+               }\r
+               if(bIsRemoteBranch)\r
+               {\r
+                       csMessage += L"\r\n\r\n<b>Warning:\r\nThis action will remove the branch on the remote.</b>";\r
+                       mbIcon = MB_ICONWARNING;\r
                }\r
        }\r
        else if(wcsncmp(completeRefName,L"refs/tags",9)==0)\r
                }\r
        }\r
        else if(wcsncmp(completeRefName,L"refs/tags",9)==0)\r
@@ -432,11 +447,26 @@ bool CBrowseRefsDlg::ConfirmDeleteRef(CString completeRefName)
 \r
 bool CBrowseRefsDlg::DoDeleteRef(CString completeRefName, bool bForce)\r
 {\r
 \r
 bool CBrowseRefsDlg::DoDeleteRef(CString completeRefName, bool bForce)\r
 {\r
-       if(wcsncmp(completeRefName,L"refs/heads",10)==0)\r
+       bool bIsRemoteBranch = false;\r
+       bool bIsBranch = false;\r
+       if              (wcsncmp(completeRefName, L"refs/remotes",12)==0)       {bIsBranch = true; bIsRemoteBranch = true;}\r
+       else if (wcsncmp(completeRefName, L"refs/heads",10)==0)         {bIsBranch = true;}\r
+\r
+       if(bIsBranch)\r
        {\r
        {\r
-               CString branchToDelete = completeRefName.Mid(11);\r
+               CString branchToDelete = completeRefName.Mid(bIsRemoteBranch ? 13 : 11);\r
                CString cmd;\r
                CString cmd;\r
-               cmd.Format(L"git.exe branch -%c %s",bForce?L'D':L'd',branchToDelete);\r
+               if(bIsRemoteBranch)\r
+               {\r
+                       int slash = branchToDelete.Find(L'/');\r
+                       if(slash < 0)\r
+                               return false;\r
+                       CString remoteName = branchToDelete.Left(slash);\r
+                       CString remoteBranchToDelete = branchToDelete.Mid(slash + 1);\r
+                       cmd.Format(L"git.exe push \"%s\" :%s", remoteName, remoteBranchToDelete);\r
+               }\r
+               else\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 resultDummy;\r
                if(g_Git.Run(cmd,&resultDummy,CP_UTF8)!=0)\r
                {\r
@@ -519,6 +549,7 @@ void CBrowseRefsDlg::ShowContextMenu(CPoint point, HTREEITEM hTreePos, VectorPSh
                bool bShowReflogOption = false;\r
                bool bShowDeleteBranchOption = false;\r
                bool bShowDeleteTagOption = false;\r
                bool bShowReflogOption = false;\r
                bool bShowDeleteBranchOption = false;\r
                bool bShowDeleteTagOption = false;\r
+               bool bShowDeleteRemoteBranchOption = false;\r
 \r
                if(selectedLeafs[0]->IsFrom(L"refs/heads"))\r
                {\r
 \r
                if(selectedLeafs[0]->IsFrom(L"refs/heads"))\r
                {\r
@@ -528,16 +559,18 @@ void CBrowseRefsDlg::ShowContextMenu(CPoint point, HTREEITEM hTreePos, VectorPSh
                else if(selectedLeafs[0]->IsFrom(L"refs/remotes"))\r
                {\r
                        bShowReflogOption = true;\r
                else if(selectedLeafs[0]->IsFrom(L"refs/remotes"))\r
                {\r
                        bShowReflogOption = true;\r
+                       bShowDeleteRemoteBranchOption = true;\r
                }\r
                else if(selectedLeafs[0]->IsFrom(L"refs/tags"))\r
                {\r
                        bShowDeleteTagOption = true;\r
                }\r
 \r
                }\r
                else if(selectedLeafs[0]->IsFrom(L"refs/tags"))\r
                {\r
                        bShowDeleteTagOption = true;\r
                }\r
 \r
-                                                                       popupMenu.AppendMenuIcon(eCmd_ViewLog, L"Show Log", IDI_LOG);\r
-               if(bShowReflogOption)           popupMenu.AppendMenuIcon(eCmd_ShowReflog, L"Show Reflog", IDI_LOG);\r
-               if(bShowDeleteTagOption)        popupMenu.AppendMenuIcon(eCmd_DeleteTag, L"Delete Tag", IDI_DELETE);\r
-               if(bShowDeleteBranchOption) popupMenu.AppendMenuIcon(eCmd_DeleteBranch, L"Delete Branch", IDI_DELETE);\r
+                                                                                       popupMenu.AppendMenuIcon(eCmd_ViewLog, L"Show Log", IDI_LOG);\r
+               if(bShowReflogOption)                           popupMenu.AppendMenuIcon(eCmd_ShowReflog, L"Show Reflog", IDI_LOG);\r
+               if(bShowDeleteTagOption)                        popupMenu.AppendMenuIcon(eCmd_DeleteTag, L"Delete Tag", IDI_DELETE);\r
+               if(bShowDeleteBranchOption)                     popupMenu.AppendMenuIcon(eCmd_DeleteBranch, L"Delete Branch", IDI_DELETE);\r
+               if(bShowDeleteRemoteBranchOption)       popupMenu.AppendMenuIcon(eCmd_DeleteRemoteBranch, L"Delete Remote Branch", IDI_DELETE);\r
 \r
 \r
 \r
 \r
 \r
 \r
@@ -574,6 +607,7 @@ void CBrowseRefsDlg::ShowContextMenu(CPoint point, HTREEITEM hTreePos, VectorPSh
                }\r
                break;\r
        case eCmd_DeleteBranch:\r
                }\r
                break;\r
        case eCmd_DeleteBranch:\r
+       case eCmd_DeleteRemoteBranch:\r
                {\r
                        if(ConfirmDeleteRef(selectedLeafs[0]->GetRefName()))\r
                                DoDeleteRef(selectedLeafs[0]->GetRefName(), true);\r
                {\r
                        if(ConfirmDeleteRef(selectedLeafs[0]->GetRefName()))\r
                                DoDeleteRef(selectedLeafs[0]->GetRefName(), true);\r
index 5bfa067..bf3fafb 100644 (file)
@@ -65,6 +65,7 @@ public:
                eCmd_CreateBranch,\r
                eCmd_CreateTag,\r
                eCmd_DeleteBranch,\r
                eCmd_CreateBranch,\r
                eCmd_CreateTag,\r
                eCmd_DeleteBranch,\r
+               eCmd_DeleteRemoteBranch,\r
                eCmd_DeleteTag,\r
                eCmd_ShowReflog\r
        };\r
                eCmd_DeleteTag,\r
                eCmd_ShowReflog\r
        };\r