Fixed issue #1116: Make remote branch in pull dialog default to the current branch...
[TortoiseGit.git] / src / TortoiseProc / PullFetchDlg.cpp
blob07649d1d63416a2a49720ca3df2ed3ed4ba888d9
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - TortoiseGit
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // PullFetchDlg.cpp : implementation file
23 #include "stdafx.h"
24 #include "TortoiseProc.h"
25 #include "PullFetchDlg.h"
26 #include "Git.h"
27 #include "AppUtils.h"
28 #include "BrowseRefsDlg.h"
29 // CPullFetchDlg dialog
31 IMPLEMENT_DYNAMIC(CPullFetchDlg, CHorizontalResizableStandAloneDialog)
33 CPullFetchDlg::CPullFetchDlg(CWnd* pParent /*=NULL*/)
34 : CHorizontalResizableStandAloneDialog(CPullFetchDlg::IDD, pParent)
36 m_IsPull=TRUE;
37 m_bAutoLoad = CAppUtils::IsSSHPutty();
38 m_bAutoLoadEnable=CAppUtils::IsSSHPutty();;
39 m_regRebase = false;
40 m_bNoFF = false;
41 m_bSquash = false;
42 m_bNoCommit = false;
43 m_bFFonly = false;
44 m_bFetchTags = false;
47 CPullFetchDlg::~CPullFetchDlg()
51 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
53 CDialog::DoDataExchange(pDX);
54 DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);
55 DDX_Control(pDX, IDC_OTHER, this->m_Other);
56 DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);
57 DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);
58 DDX_Check(pDX,IDC_CHECK_NOFF, this->m_bNoFF);
59 DDX_Check(pDX,IDC_CHECK_SQUASH, this->m_bSquash);
60 DDX_Check(pDX,IDC_CHECK_NOCOMMIT, this->m_bNoCommit);
61 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);
62 DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);
63 DDX_Check(pDX,IDC_CHECK_PRUNE,m_bPrune);
64 DDX_Check(pDX, IDC_CHECK_FFONLY, m_bFFonly);
65 DDX_Check(pDX, IDC_CHECK_FETCHTAGS, m_bFetchTags);
69 BEGIN_MESSAGE_MAP(CPullFetchDlg, CHorizontalResizableStandAloneDialog)
70 ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)
71 ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)
72 ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)
73 ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)
74 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)
75 END_MESSAGE_MAP()
77 BOOL CPullFetchDlg::OnInitDialog()
79 CHorizontalResizableStandAloneDialog::OnInitDialog();
80 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
82 AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);
83 AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);
85 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
86 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT);
88 AddAnchor(IDOK,BOTTOM_RIGHT);
89 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
90 AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,TOP_RIGHT);
91 AddAnchor(IDC_GROUP_OPTION,TOP_LEFT,TOP_RIGHT);
92 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);
93 AddAnchor(IDC_CHECK_PRUNE,BOTTOM_LEFT);
94 AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);
95 AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);
96 AddAnchor(IDHELP, BOTTOM_RIGHT);
98 CString WorkingDir=g_Git.m_CurrentDir;
99 WorkingDir.Replace(_T(':'),_T('_'));
101 m_RemoteReg = CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
102 CString regkey;
103 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
104 m_regRebase=CRegDWORD(regkey,false);
105 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir,this->m_IsPull);
107 m_regAutoLoadPutty = CRegDWORD(regkey,this->m_bAutoLoad);
108 m_bAutoLoad = m_regAutoLoadPutty;
110 if(!CAppUtils::IsSSHPutty())
111 m_bAutoLoad = false;
113 if(m_bAllowRebase)
115 this->m_bRebase = m_regRebase;
117 else
119 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
120 this->m_bRebase = FALSE;
123 this->UpdateData(FALSE);
125 this->AddOthersToAnchor();
127 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
129 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
130 m_Remote.EnableWindow(TRUE);
131 m_Other.EnableWindow(FALSE);
132 if(!m_IsPull)
133 m_RemoteBranch.EnableWindow(FALSE);
135 if(m_IsPull)
137 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
138 GetDlgItem(IDC_CHECK_PRUNE)->ShowWindow(SW_HIDE);
139 GetDlgItem(IDC_CHECK_FETCHTAGS)->EnableWindow(FALSE);
141 else
143 this->GetDlgItem(IDC_GROUP_OPTION)->EnableWindow(FALSE);
144 this->GetDlgItem(IDC_CHECK_SQUASH)->EnableWindow(FALSE);
145 this->GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(FALSE);
146 this->GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(FALSE);
147 this->GetDlgItem(IDC_CHECK_NOCOMMIT)->EnableWindow(FALSE);
150 if (g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir))
151 this->GetDlgItem(IDC_CHECK_REBASE)->EnableWindow(FALSE);
153 m_Other.SetURLHistory(TRUE);
154 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
155 CString clippath=CAppUtils::GetClipboardLink();
156 if(clippath.IsEmpty())
157 m_Other.SetCurSel(0);
158 else
159 m_Other.SetWindowText(clippath);
161 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
162 m_RemoteBranch.SetCurSel(0);
164 CString sWindowTitle;
165 if(m_IsPull)
166 sWindowTitle = _T("Pull");
167 else
168 sWindowTitle = _T("Fetch");
170 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
172 Refresh();
174 EnableSaveRestore(_T("PullFetchDlg"));
175 this->m_RemoteManage.SetURL(CString());
176 return TRUE;
179 void CPullFetchDlg::Refresh()
181 //Select pull-remote from current branch
182 CString currentBranch = g_Git.GetSymbolicRef();
183 CString configName;
184 configName.Format(L"branch.%s.remote", currentBranch);
185 CString pullRemote = this->m_configPullRemote = g_Git.GetConfigValue(configName);
187 //Select pull-branch from current branch
188 configName.Format(L"branch.%s.merge", currentBranch);
189 CString pullBranch = m_configPullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
190 if (pullBranch.IsEmpty())
191 m_RemoteBranch.AddString(currentBranch);
192 else
193 m_RemoteBranch.AddString(pullBranch);
195 if(pullRemote.IsEmpty())
196 pullRemote = m_RemoteReg;
198 if (!m_PreSelectRemote.IsEmpty())
199 pullRemote = m_PreSelectRemote;
201 STRING_VECTOR list;
202 int sel=0;
203 if(!g_Git.GetRemoteList(list))
205 for(unsigned int i=0;i<list.size();i++)
207 m_Remote.AddString(list[i]);
208 if(list[i] == pullRemote)
209 sel = i;
212 m_Remote.SetCurSel(sel);
214 // CPullFetchDlg message handlers
216 void CPullFetchDlg::OnBnClickedRd()
218 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
220 m_Remote.EnableWindow(TRUE);
221 m_Other.EnableWindow(FALSE);
222 if(!m_IsPull)
223 m_RemoteBranch.EnableWindow(FALSE);
225 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
227 m_Remote.EnableWindow(FALSE);
228 m_Other.EnableWindow(TRUE);;
229 if(!m_IsPull)
230 m_RemoteBranch.EnableWindow(TRUE);
234 void CPullFetchDlg::OnBnClickedOk()
236 this->UpdateData();
237 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
239 m_RemoteURL=m_Remote.GetString();
240 if( !m_IsPull ||
241 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
242 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
243 //because otherwise git will not update the remote tracking branches.
244 m_RemoteBranchName.Empty();
245 else
246 m_RemoteBranchName=m_RemoteBranch.GetString();
248 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
250 m_Other.GetWindowTextW(m_RemoteURL);
251 m_RemoteBranchName=m_RemoteBranch.GetString();
254 m_RemoteReg = m_Remote.GetString();
256 m_Other.SaveHistory();
257 m_RemoteBranch.SaveHistory();
258 this->m_regRebase=this->m_bRebase;
260 m_regAutoLoadPutty = m_bAutoLoad;
262 this->OnOK();
265 void CPullFetchDlg::OnStnClickedRemoteManage()
267 CAppUtils::LaunchRemoteSetting();
268 Refresh();
271 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
273 CString initialRef;
274 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
275 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
276 if(selectedRef.Left(13) != "refs/remotes/")
277 return;
279 selectedRef = selectedRef.Mid(13);
280 int ixSlash = selectedRef.Find('/');
282 CString remoteName = selectedRef.Left(ixSlash);
283 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
285 int ixFound = m_Remote.FindStringExact(0, remoteName);
286 if(ixFound >= 0)
287 m_Remote.SetCurSel(ixFound);
288 m_RemoteBranch.AddString(remoteBranch);
290 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);