OSDN Git Service

Fixed issue #150: When pushing, 'remote' should default to the tracked branch, or...
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / PushDlg.cpp
index 8f181be..22557d0 100644 (file)
@@ -8,6 +8,7 @@
 #include "Git.h"\r
 #include "registry.h"\r
 #include "AppUtils.h"\r
+#include "BrowseRefsDlg.h"\r
 \r
 // CPushDlg dialog\r
 \r
@@ -44,6 +45,8 @@ BEGIN_MESSAGE_MAP(CPushDlg, CResizableStandAloneDialog)
        ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE, &CPushDlg::OnCbnSelchangeBranchSource)\r
        ON_BN_CLICKED(IDOK, &CPushDlg::OnBnClickedOk)\r
     ON_BN_CLICKED(IDC_REMOTE_MANAGE, &CPushDlg::OnBnClickedRemoteManage)\r
+       ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH, &CPushDlg::OnBnClickedButtonBrowseSourceBranch)\r
+       ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH, &CPushDlg::OnBnClickedButtonBrowseDestBranch)\r
 END_MESSAGE_MAP()\r
 \r
 BOOL CPushDlg::OnInitDialog()\r
@@ -57,7 +60,9 @@ BOOL CPushDlg::OnInitDialog()
        AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);\r
 \r
        AddAnchor(IDC_BRANCH_REMOTE, TOP_RIGHT);\r
+       AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);\r
        AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT);\r
+       AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_LEFT);\r
 \r
        AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);\r
        AddAnchor(IDC_RD_REMOTE, TOP_LEFT);\r
@@ -75,6 +80,7 @@ BOOL CPushDlg::OnInitDialog()
     AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);\r
 \r
     AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);\r
+       AddAnchor(IDHELP, BOTTOM_RIGHT);\r
 \r
        AddOthersToAnchor();\r
 \r
@@ -87,16 +93,60 @@ BOOL CPushDlg::OnInitDialog()
        CString WorkingDir=g_Git.m_CurrentDir;\r
        WorkingDir.Replace(_T(':'),_T('_'));\r
        m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));\r
-       m_RemoteURL.SetCurSel(0);\r
+       CString clippath=CAppUtils::GetClipboardLink();\r
+       if(clippath.IsEmpty())\r
+               m_RemoteURL.SetCurSel(0);\r
+       else\r
+               m_RemoteURL.SetWindowText(clippath);\r
 \r
        m_RemoteURL.EnableWindow(FALSE);\r
        CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);\r
 \r
-       STRING_VECTOR list;\r
+\r
+       Refresh();\r
+\r
+\r
+       //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());\r
+\r
+       \r
+       return TRUE;\r
+}\r
+\r
+void CPushDlg::Refresh()\r
+{\r
+       CString WorkingDir=g_Git.m_CurrentDir;\r
+       WorkingDir.Replace(_T(':'),_T('_'));\r
+\r
        CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));\r
        m_RemoteReg = remote;\r
        int sel=0;\r
 \r
+       CString currentBranch = g_Git.GetSymbolicRef();\r
+       CString configName;\r
+\r
+       configName.Format(L"branch.%s.pushremote", currentBranch);\r
+       CString pushRemote = g_Git.GetConfigValue(configName);\r
+       if( pushRemote.IsEmpty() )\r
+       {\r
+               configName.Format(L"branch.%s.remote", currentBranch);\r
+               pushRemote = g_Git.GetConfigValue(configName);\r
+       }\r
+\r
+       if( !pushRemote.IsEmpty() )\r
+               remote=pushRemote;\r
+\r
+       //Select pull-branch from current branch\r
+       configName.Format(L"branch.%s.pushbranch", currentBranch);\r
+       CString pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));\r
+       if( pushBranch.IsEmpty() )\r
+       {\r
+               configName.Format(L"branch.%s.merge", currentBranch);\r
+               pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));              \r
+       }\r
+\r
+       STRING_VECTOR list;\r
+       m_Remote.Reset();\r
+\r
        if(!g_Git.GetRemoteList(list))\r
        {       \r
                for(unsigned int i=0;i<list.size();i++)\r
@@ -110,22 +160,24 @@ BOOL CPushDlg::OnInitDialog()
 \r
        int current=0;\r
        list.clear();\r
+       m_BranchSource.Reset();\r
        if(!g_Git.GetBranchList(list,&current))\r
        {\r
                for(unsigned int i=0;i<list.size();i++)\r
                        m_BranchSource.AddString(list[i]);\r
        }\r
        m_BranchSource.SetCurSel(current);\r
-       \r
-       m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));\r
-       m_BranchRemote.SetCurSel(0);\r
 \r
-       //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());\r
+       m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));\r
+       if( !pushBranch.IsEmpty() )\r
+       {\r
+               m_BranchRemote.AddString(pushBranch);\r
+               m_BranchRemote.SetCurSel(0);    \r
+       }\r
+       else\r
+               m_BranchRemote.SetCurSel(-1);\r
 \r
-       \r
-       return TRUE;\r
 }\r
-\r
 // CPushDlg message handlers\r
 \r
 void CPushDlg::OnBnClickedRd()\r
@@ -148,7 +200,7 @@ void CPushDlg::OnBnClickedRd()
 void CPushDlg::OnCbnSelchangeBranchSource()\r
 {\r
        // TODO: Add your control notification handler code here\r
-       m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());\r
+       m_BranchRemote.AddString(m_BranchSource.GetString());\r
 }\r
 \r
 void CPushDlg::OnBnClickedOk()\r
@@ -181,3 +233,50 @@ void CPushDlg::OnBnClickedRemoteManage()
     // TODO: Add your control notification handler code here\r
     CAppUtils::LaunchRemoteSetting();\r
 }\r
+\r
+void CPushDlg::OnBnClickedButtonBrowseSourceBranch()\r
+{\r
+       if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))\r
+               OnCbnSelchangeBranchSource();\r
+}\r
+\r
+void CPushDlg::OnBnClickedButtonBrowseDestBranch()\r
+{\r
+       CString remoteBranchName;\r
+       CString remoteName;\r
+       m_BranchRemote.GetWindowText(remoteBranchName);\r
+       remoteName = m_Remote.GetString();\r
+       remoteBranchName = remoteName + '/' + remoteBranchName;\r
+       remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);\r
+       if(remoteBranchName.IsEmpty())\r
+               return; //Canceled\r
+       remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'\r
+       int slashPlace = remoteBranchName.Find('/');\r
+       remoteName = remoteBranchName.Left(slashPlace);\r
+       remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')\r
+\r
+       //Select remote\r
+       int remoteSel = m_Remote.FindStringExact(0,remoteName);\r
+       if(remoteSel >= 0)\r
+               m_Remote.SetCurSel(remoteSel);\r
+\r
+       //Select branch\r
+       m_BranchRemote.AddString(remoteBranchName);\r
+}\r
+\r
+BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)\r
+{\r
+       if (pMsg->message == WM_KEYDOWN)\r
+       {\r
+               switch (pMsg->wParam)\r
+               {\r
+               case VK_F5:\r
+                       {\r
+                               Refresh();\r
+                       }\r
+                       break;\r
+               }\r
+       }\r
+\r
+       return CResizableStandAloneDialog::PreTranslateMessage(pMsg);\r
+}\r