OSDN Git Service

Fixed issue #150: When pushing, 'remote' should default to the tracked branch, or...
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / PushDlg.cpp
index 8f35c3d..22557d0 100644 (file)
@@ -6,6 +6,10 @@
 #include "PushDlg.h"\r
 \r
 #include "Git.h"\r
+#include "registry.h"\r
+#include "AppUtils.h"\r
+#include "BrowseRefsDlg.h"\r
+\r
 // CPushDlg dialog\r
 \r
 IMPLEMENT_DYNAMIC(CPushDlg, CResizableStandAloneDialog)\r
@@ -13,7 +17,7 @@ IMPLEMENT_DYNAMIC(CPushDlg, CResizableStandAloneDialog)
 CPushDlg::CPushDlg(CWnd* pParent /*=NULL*/)\r
        : CResizableStandAloneDialog(CPushDlg::IDD, pParent)\r
 {\r
-\r
+    m_bAutoLoad = CAppUtils::IsSSHPutty();\r
 }\r
 \r
 CPushDlg::~CPushDlg()\r
@@ -30,6 +34,7 @@ void CPushDlg::DoDataExchange(CDataExchange* pDX)
        DDX_Check(pDX,IDC_FORCE,this->m_bForce);\r
        DDX_Check(pDX,IDC_PACK,this->m_bPack);\r
        DDX_Check(pDX,IDC_TAGS,this->m_bTags);\r
+    DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,this->m_bAutoLoad);\r
 \r
 }\r
 \r
@@ -39,62 +44,140 @@ BEGIN_MESSAGE_MAP(CPushDlg, CResizableStandAloneDialog)
        ON_BN_CLICKED(IDC_RD_URL, &CPushDlg::OnBnClickedRd)\r
        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
 {\r
        CResizableStandAloneDialog::OnInitDialog();\r
        \r
+       AddAnchor(IDOK,BOTTOM_RIGHT);\r
+       AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
+       AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);\r
+       AddAnchor(IDC_STATIC_REMOTE, TOP_RIGHT);\r
+       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
+       AddAnchor(IDC_RD_URL, TOP_LEFT);\r
 \r
        AddAnchor(IDC_REMOTE, TOP_LEFT, TOP_RIGHT);\r
+       \r
        AddAnchor(IDC_URL, TOP_LEFT,TOP_RIGHT);\r
 \r
-       AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);\r
        AddAnchor(IDC_OPTION_GROUP, TOP_LEFT,TOP_RIGHT);\r
-       AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);\r
+       \r
+       AddAnchor(IDC_FORCE, TOP_LEFT);\r
+       AddAnchor(IDC_PACK, TOP_LEFT);\r
+       AddAnchor(IDC_TAGS, TOP_LEFT);\r
+    AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);\r
 \r
-       AddAnchor(IDC_STATIC_REMOTE, TOP_RIGHT);\r
+    AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);\r
+       AddAnchor(IDHELP, BOTTOM_RIGHT);\r
 \r
-       AddAnchor(IDOK,BOTTOM_RIGHT);\r
-       AddAnchor(IDCANCEL,BOTTOM_RIGHT);\r
+       AddOthersToAnchor();\r
+\r
+    this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoad);\r
 \r
        EnableSaveRestore(_T("PushDlg"));\r
 \r
        m_RemoteURL.SetURLHistory(TRUE);\r
-       m_RemoteURL.LoadHistory(_T("Software\\TortoiseGit\\History\\PushURLS"), _T("url"));\r
-       m_RemoteURL.SetCurSel(0);\r
+       \r
+       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
+       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
+\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
+               {\r
                        m_Remote.AddString(list[i]);\r
+                       if(list[i] == remote)\r
+                               sel = i;\r
+               }\r
        }\r
+       m_Remote.SetCurSel(sel);\r
 \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(_T("Software\\TortoiseGit\\History\\RemoteBranch"), _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
@@ -117,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
@@ -139,5 +222,61 @@ void CPushDlg::OnBnClickedOk()
 \r
        this->m_RemoteURL.SaveHistory();\r
        this->m_BranchRemote.SaveHistory();\r
+       \r
+       m_RemoteReg = m_Remote.GetString();\r
+\r
        CResizableStandAloneDialog::OnOK();\r
 }\r
+\r
+void CPushDlg::OnBnClickedRemoteManage()\r
+{\r
+    // 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