Fixed issue #492: Fix AutoLoad Putty Key operation in push dialog
[TortoiseGit.git] / src / TortoiseProc / PullFetchDlg.cpp
blob5b1a16283800b1cbd143b458a9050f48eb59afed
1 // PullFetchDlg.cpp : implementation file
2 //
4 #include "stdafx.h"
5 #include "TortoiseProc.h"
6 #include "PullFetchDlg.h"
7 #include "Git.h"
8 #include "AppUtils.h"
9 #include "BrowseRefsDlg.h"
10 // CPullFetchDlg dialog
12 IMPLEMENT_DYNAMIC(CPullFetchDlg, CResizableStandAloneDialog)
14 CPullFetchDlg::CPullFetchDlg(CWnd* pParent /*=NULL*/)
15 : CResizableStandAloneDialog(CPullFetchDlg::IDD, pParent)
17 m_IsPull=TRUE;
18 m_bAutoLoad = CAppUtils::IsSSHPutty();
19 m_bAutoLoadEnable=CAppUtils::IsSSHPutty();;
20 m_regRebase = false;
23 CPullFetchDlg::~CPullFetchDlg()
27 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
29 CDialog::DoDataExchange(pDX);
30 DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);
31 DDX_Control(pDX, IDC_OTHER, this->m_Other);
32 DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);
33 DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);
34 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);
35 DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);
40 BEGIN_MESSAGE_MAP(CPullFetchDlg,CResizableStandAloneDialog )
41 ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)
42 ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)
43 ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)
44 ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)
45 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)
46 END_MESSAGE_MAP()
48 BOOL CPullFetchDlg::OnInitDialog()
50 CResizableStandAloneDialog::OnInitDialog();
51 AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);
52 AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);
54 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
56 AddAnchor(IDOK,BOTTOM_RIGHT);
57 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
58 AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,BOTTOM_RIGHT);
59 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);
60 AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);
61 AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);
62 AddAnchor(IDHELP, BOTTOM_RIGHT);
64 CString WorkingDir=g_Git.m_CurrentDir;
65 WorkingDir.Replace(_T(':'),_T('_'));
67 CString regkey ;
68 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
69 m_regRebase=CRegDWORD(regkey,false);
70 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir,this->m_IsPull);
72 m_regAutoLoadPutty = CRegDWORD(regkey,this->m_bAutoLoad);
73 m_bAutoLoad = m_regAutoLoadPutty;
75 if(!CAppUtils::IsSSHPutty())
76 m_bAutoLoad = false;
78 this->m_bRebase = m_regRebase;
80 this->UpdateData(FALSE);
82 this->AddOthersToAnchor();
84 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
86 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
87 m_Remote.EnableWindow(TRUE);
88 m_Other.EnableWindow(FALSE);
89 if(!m_IsPull)
90 m_RemoteBranch.EnableWindow(FALSE);
92 if(m_IsPull)
93 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
95 m_Other.SetURLHistory(TRUE);
96 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
97 CString clippath=CAppUtils::GetClipboardLink();
98 if(clippath.IsEmpty())
99 m_Other.SetCurSel(0);
100 else
101 m_Other.SetWindowText(clippath);
103 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
104 m_RemoteBranch.SetCurSel(0);
106 if(m_IsPull)
107 this->SetWindowTextW(CString(_T("Pull - "))+WorkingDir);
108 else
109 this->SetWindowTextW(CString(_T("Fetch - "))+WorkingDir);
111 STRING_VECTOR list;
113 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
114 m_RemoteReg = remote;
115 int sel=0;
117 //Select pull-remote from current branch
118 CString currentBranch = g_Git.GetSymbolicRef();
119 CString configName;
120 configName.Format(L"branch.%s.remote", currentBranch);
121 CString pullRemote = m_configPullRemote = g_Git.GetConfigValue(configName);
123 //Select pull-branch from current branch
124 configName.Format(L"branch.%s.merge", currentBranch);
125 CString pullBranch = m_configPullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
126 m_RemoteBranch.AddString(pullBranch);
128 if(pullRemote.IsEmpty())
129 pullRemote = remote;
131 if(!g_Git.GetRemoteList(list))
133 for(unsigned int i=0;i<list.size();i++)
135 m_Remote.AddString(list[i]);
136 if(list[i] == pullRemote)
137 sel = i;
140 m_Remote.SetCurSel(sel);
142 EnableSaveRestore(_T("PullFetchDlg"));
143 this->m_RemoteManage.SetURL(CString());
144 return TRUE;
146 // CPullFetchDlg message handlers
148 void CPullFetchDlg::OnBnClickedRd()
151 // TODO: Add your control notification handler code here
152 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
154 m_Remote.EnableWindow(TRUE);
155 m_Other.EnableWindow(FALSE);
156 if(!m_IsPull)
157 m_RemoteBranch.EnableWindow(FALSE);
159 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
161 m_Remote.EnableWindow(FALSE);
162 m_Other.EnableWindow(TRUE);;
163 if(!m_IsPull)
164 m_RemoteBranch.EnableWindow(TRUE);
170 void CPullFetchDlg::OnBnClickedOk()
172 this->UpdateData();
173 // TODO: Add your control notification handler code here
174 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
176 m_RemoteURL=m_Remote.GetString();
177 if( !m_IsPull ||
178 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
179 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
180 //because otherwise git will not update the remote tracking branches.
181 m_RemoteBranchName.Empty();
182 else
183 m_RemoteBranchName=m_RemoteBranch.GetString();
186 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
188 m_Other.GetWindowTextW(m_RemoteURL);
189 m_RemoteBranchName=m_RemoteBranch.GetString();
193 m_RemoteReg = m_Remote.GetString();
195 m_Other.SaveHistory();
196 m_RemoteBranch.SaveHistory();
197 this->m_regRebase=this->m_bRebase;
199 m_regAutoLoadPutty = m_bAutoLoad;
201 this->OnOK();
204 void CPullFetchDlg::OnStnClickedRemoteManage()
206 // TODO: Add your control notification handler code here
207 CAppUtils::LaunchRemoteSetting();
210 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
212 CString initialRef;
213 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
214 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
215 if(selectedRef.Left(13) != "refs/remotes/")
216 return;
218 selectedRef = selectedRef.Mid(13);
219 int ixSlash = selectedRef.Find('/');
221 CString remoteName = selectedRef.Left(ixSlash);
222 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
224 int ixFound = m_Remote.FindStringExact(0, remoteName);
225 if(ixFound >= 0)
226 m_Remote.SetCurSel(ixFound);
227 m_RemoteBranch.AddString(remoteBranch);
229 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);