Use translated string for "- all -"
[TortoiseGit.git] / src / TortoiseProc / PullFetchDlg.cpp
blob9adde056d4dc55d4ab231cd72ace275193f5939e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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_bAllowRebase = false;
38 m_bAutoLoad = CAppUtils::IsSSHPutty();
39 m_bAutoLoadEnable=CAppUtils::IsSSHPutty();;
40 m_regRebase = false;
41 m_bNoFF = false;
42 m_bRebase = FALSE;
43 m_bSquash = false;
44 m_bNoCommit = false;
45 m_bFFonly = false;
46 m_bFetchTags = 2;
47 m_bAllRemotes = FALSE;
48 m_bPrune = CAppUtils::GetMsysgitVersion() >= 0x01080500 ? 2 : FALSE;
51 CPullFetchDlg::~CPullFetchDlg()
55 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
57 CDialog::DoDataExchange(pDX);
58 DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);
59 DDX_Control(pDX, IDC_OTHER, this->m_Other);
60 DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);
61 DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);
62 DDX_Check(pDX,IDC_CHECK_NOFF, this->m_bNoFF);
63 DDX_Check(pDX,IDC_CHECK_SQUASH, this->m_bSquash);
64 DDX_Check(pDX,IDC_CHECK_NOCOMMIT, this->m_bNoCommit);
65 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);
66 DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);
67 DDX_Check(pDX,IDC_CHECK_PRUNE,m_bPrune);
68 DDX_Check(pDX, IDC_CHECK_FFONLY, m_bFFonly);
69 DDX_Check(pDX, IDC_CHECK_FETCHTAGS, m_bFetchTags);
73 BEGIN_MESSAGE_MAP(CPullFetchDlg, CHorizontalResizableStandAloneDialog)
74 ON_CBN_SELCHANGE(IDC_REMOTE_COMBO, &CPullFetchDlg::OnCbnSelchangeRemote)
75 ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)
76 ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)
77 ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)
78 ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)
79 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)
80 ON_BN_CLICKED(IDC_CHECK_FFONLY, OnBnClickedCheckFfonly)
81 ON_BN_CLICKED(IDC_CHECK_NOFF, OnBnClickedCheckFfonly)
82 END_MESSAGE_MAP()
84 BOOL CPullFetchDlg::OnInitDialog()
86 CHorizontalResizableStandAloneDialog::OnInitDialog();
87 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
89 AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);
90 AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);
92 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
93 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT);
95 AddAnchor(IDOK,BOTTOM_RIGHT);
96 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
97 AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,TOP_RIGHT);
98 AddAnchor(IDC_GROUP_OPTION,TOP_LEFT,TOP_RIGHT);
99 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);
100 AddAnchor(IDC_CHECK_PRUNE,BOTTOM_LEFT);
101 AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);
102 AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);
103 AddAnchor(IDHELP, BOTTOM_RIGHT);
105 AdjustControlSize(IDC_REMOTE_RD);
106 AdjustControlSize(IDC_OTHER_RD);
107 AdjustControlSize(IDC_CHECK_SQUASH);
108 AdjustControlSize(IDC_CHECK_NOCOMMIT);
109 AdjustControlSize(IDC_CHECK_NOFF);
110 AdjustControlSize(IDC_CHECK_FFONLY);
111 AdjustControlSize(IDC_CHECK_FETCHTAGS);
112 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD);
113 AdjustControlSize(IDC_CHECK_REBASE);
114 AdjustControlSize(IDC_CHECK_PRUNE);
116 CString WorkingDir=g_Git.m_CurrentDir;
117 WorkingDir.Replace(_T(':'),_T('_'));
119 m_RemoteReg = CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
120 CString regkey;
121 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
122 m_regRebase=CRegDWORD(regkey,false);
123 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\ffonly"), WorkingDir, m_IsPull);
124 m_regFFonly = CRegDWORD(regkey, false);
125 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir,this->m_IsPull);
127 m_regAutoLoadPutty = CRegDWORD(regkey,this->m_bAutoLoad);
128 m_bAutoLoad = m_regAutoLoadPutty;
130 if(!CAppUtils::IsSSHPutty())
131 m_bAutoLoad = false;
133 if(m_bAllowRebase)
135 this->m_bRebase = m_regRebase;
137 else
139 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
140 this->m_bRebase = FALSE;
143 this->UpdateData(FALSE);
145 this->AddOthersToAnchor();
147 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
149 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
150 m_Remote.EnableWindow(TRUE);
151 m_Other.EnableWindow(FALSE);
152 if(!m_IsPull)
154 m_RemoteBranch.EnableWindow(FALSE);
155 GetDlgItem(IDC_BUTTON_BROWSE_REF)->EnableWindow(FALSE);
158 if(m_IsPull)
160 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
161 // check tags checkbox and make it a normal checkbox
162 m_bFetchTags = 1;
163 m_bFFonly = m_regFFonly;
164 UpdateData(FALSE);
165 ::SendMessage(GetDlgItem(IDC_CHECK_FETCHTAGS)->GetSafeHwnd(), BM_SETSTYLE, GetDlgItem(IDC_CHECK_FETCHTAGS)->GetStyle() & ~BS_AUTO3STATE | BS_AUTOCHECKBOX, 0);
166 OnBnClickedCheckFfonly();
168 else
170 this->GetDlgItem(IDC_GROUP_OPTION)->EnableWindow(FALSE);
171 this->GetDlgItem(IDC_CHECK_SQUASH)->EnableWindow(FALSE);
172 this->GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(FALSE);
173 this->GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(FALSE);
174 this->GetDlgItem(IDC_CHECK_NOCOMMIT)->EnableWindow(FALSE);
177 if (g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir))
178 this->GetDlgItem(IDC_CHECK_REBASE)->EnableWindow(FALSE);
180 m_Other.SetCaseSensitive(TRUE);
181 m_Other.SetURLHistory(TRUE);
182 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
184 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
185 m_RemoteBranch.SetCurSel(0);
187 CString sWindowTitle;
188 if(m_IsPull)
189 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_PULL));
190 else
191 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH));
193 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
195 Refresh();
197 EnableSaveRestore(_T("PullFetchDlg"));
198 this->m_RemoteManage.SetURL(CString());
199 return TRUE;
202 void CPullFetchDlg::Refresh()
204 //Select pull-remote from current branch
205 CString currentBranch;
206 if (g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir, currentBranch))
207 currentBranch.Empty();
209 CString pullRemote, pullBranch;
210 g_Git.GetRemoteTrackedBranch(currentBranch, pullRemote, pullBranch);
211 m_configPullRemote = pullRemote;
212 m_configPullBranch = pullBranch;
214 if (pullBranch.IsEmpty())
215 m_RemoteBranch.AddString(currentBranch);
216 else
217 m_RemoteBranch.AddString(pullBranch);
219 if(pullRemote.IsEmpty())
220 pullRemote = m_RemoteReg;
222 if (!m_PreSelectRemote.IsEmpty())
223 pullRemote = m_PreSelectRemote;
225 STRING_VECTOR list;
226 m_Remote.Reset();
227 int sel=0;
228 if(!g_Git.GetRemoteList(list))
230 if (!m_IsPull && list.size() > 1)
231 m_Remote.AddString(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)));
233 for (unsigned int i = 0; i < list.size(); ++i)
235 m_Remote.AddString(list[i]);
236 if (!m_bAllRemotes && list[i] == pullRemote)
237 sel = i + (!m_IsPull && list.size() > 1 ? 1 : 0);
240 m_Remote.SetCurSel(sel);
241 OnCbnSelchangeRemote();
243 // CPullFetchDlg message handlers
245 void CPullFetchDlg::OnCbnSelchangeRemote()
247 CString remote = m_Remote.GetString();
248 if (remote.IsEmpty() || remote == CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)))
250 GetDlgItem(IDC_STATIC_TAGOPT)->SetWindowText(_T(""));
251 GetDlgItem(IDC_STATIC_PRUNE)->SetWindowText(_T(""));
252 return;
255 CString key;
256 key.Format(_T("remote.%s.tagopt"), remote);
257 CString tagopt = g_Git.GetConfigValue(key);
258 if (tagopt == "--no-tags")
259 tagopt = CString(MAKEINTRESOURCE(IDS_NONE));
260 else if (tagopt == "--tags")
261 tagopt = CString(MAKEINTRESOURCE(CAppUtils::GetMsysgitVersion() < 0x01090000 ? IDS_FETCH_TAGS_ONLY : IDS_ALL));
262 else
263 tagopt = CString(MAKEINTRESOURCE(IDS_FETCH_REACHABLE));
264 CString value;
265 value.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT)), tagopt);
266 GetDlgItem(IDC_STATIC_TAGOPT)->SetWindowText(value);
268 CString prune;
269 if (CAppUtils::GetMsysgitVersion() >= 0x01080500)
271 key.Format(_T("remote.%s.prune"), remote);
272 prune = g_Git.GetConfigValue(key);
273 if (prune.IsEmpty())
274 prune = g_Git.GetConfigValue(_T("fetch.prune"));
276 if (!prune.IsEmpty())
278 CString value;
279 value.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT)), prune);
280 GetDlgItem(IDC_STATIC_PRUNE)->SetWindowText(value);
282 else
283 GetDlgItem(IDC_STATIC_PRUNE)->SetWindowText(_T(""));
286 void CPullFetchDlg::OnBnClickedRd()
288 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
290 m_Remote.EnableWindow(TRUE);
291 m_Other.EnableWindow(FALSE);
292 if(!m_IsPull)
293 m_RemoteBranch.EnableWindow(FALSE);
295 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
297 CString clippath = CAppUtils::GetClipboardLink(m_IsPull ? _T("git pull") : _T("git fetch"), 1);
298 if (clippath.IsEmpty())
299 m_Other.SetCurSel(0);
300 else
302 int argSeparator = clippath.Find(' ');
303 if (argSeparator > 1 && clippath.GetLength() > argSeparator + 2)
305 m_Other.SetWindowText(clippath.Left(argSeparator));
306 m_RemoteBranch.SetWindowText(clippath.Mid(argSeparator + 1));
308 else
309 m_Other.SetWindowText(clippath);
311 m_Remote.EnableWindow(FALSE);
312 m_Other.EnableWindow(TRUE);;
313 if(!m_IsPull)
314 m_RemoteBranch.EnableWindow(TRUE);
318 void CPullFetchDlg::OnBnClickedOk()
320 this->UpdateData();
321 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
323 m_RemoteURL=m_Remote.GetString();
324 m_bAllRemotes = (m_Remote.GetCurSel() == 0 && m_Remote.GetCount() > 1 && !m_IsPull);
325 if( !m_IsPull ||
326 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
327 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
328 //because otherwise git will not update the remote tracking branches.
329 m_RemoteBranchName.Empty();
330 else
331 m_RemoteBranchName=m_RemoteBranch.GetString();
333 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
335 m_Other.GetWindowTextW(m_RemoteURL);
336 m_RemoteBranchName=m_RemoteBranch.GetString();
338 // only store URL in history if it's value was used
339 m_Other.SaveHistory();
342 m_RemoteReg = m_Remote.GetString();
344 m_RemoteBranch.SaveHistory();
345 this->m_regRebase=this->m_bRebase;
346 m_regFFonly = m_bFFonly;
348 m_regAutoLoadPutty = m_bAutoLoad;
350 this->OnOK();
353 void CPullFetchDlg::OnStnClickedRemoteManage()
355 CAppUtils::LaunchRemoteSetting();
356 Refresh();
359 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
361 CString initialRef;
362 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
363 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
364 if(selectedRef.Left(13) != "refs/remotes/")
365 return;
367 selectedRef = selectedRef.Mid(13);
368 int ixSlash = selectedRef.Find('/');
370 CString remoteName = selectedRef.Left(ixSlash);
371 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
373 int ixFound = m_Remote.FindStringExact(0, remoteName);
374 if(ixFound >= 0)
375 m_Remote.SetCurSel(ixFound);
376 m_RemoteBranch.AddString(remoteBranch, 0);
378 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
381 void CPullFetchDlg::OnBnClickedCheckFfonly()
383 UpdateData();
384 if (m_bNoFF)
386 m_bFFonly = FALSE;
387 GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(FALSE);
389 else
391 GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(TRUE);
393 if (m_bFFonly)
395 m_bNoFF = FALSE;
396 GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(FALSE);
398 else
400 GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(TRUE);
402 UpdateData(FALSE);