Show depth option only when repository is shallow
[TortoiseGit.git] / src / TortoiseProc / PullFetchDlg.cpp
blobc260f7f0030b4fe36801321a723599b6e495faf1
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_nDepth = 1;
46 m_bDepth = FALSE;
47 m_bFFonly = false;
48 m_bFetchTags = 2;
49 m_bAllRemotes = FALSE;
50 m_bPrune = CAppUtils::GetMsysgitVersion() >= 0x01080500 ? 2 : FALSE;
53 CPullFetchDlg::~CPullFetchDlg()
57 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
59 CDialog::DoDataExchange(pDX);
60 DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);
61 DDX_Control(pDX, IDC_OTHER, this->m_Other);
62 DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);
63 DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);
64 DDX_Check(pDX,IDC_CHECK_NOFF, this->m_bNoFF);
65 DDX_Check(pDX,IDC_CHECK_SQUASH, this->m_bSquash);
66 DDX_Check(pDX,IDC_CHECK_NOCOMMIT, this->m_bNoCommit);
67 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);
68 DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);
69 DDX_Check(pDX,IDC_CHECK_PRUNE,m_bPrune);
70 DDX_Check(pDX, IDC_CHECK_DEPTH, m_bDepth);
71 DDX_Text(pDX, IDC_EDIT_DEPTH, m_nDepth);
72 DDX_Check(pDX, IDC_CHECK_FFONLY, m_bFFonly);
73 DDX_Check(pDX, IDC_CHECK_FETCHTAGS, m_bFetchTags);
77 BEGIN_MESSAGE_MAP(CPullFetchDlg, CHorizontalResizableStandAloneDialog)
78 ON_CBN_SELCHANGE(IDC_REMOTE_COMBO, &CPullFetchDlg::OnCbnSelchangeRemote)
79 ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)
80 ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)
81 ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)
82 ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)
83 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)
84 ON_BN_CLICKED(IDC_CHECK_DEPTH, OnBnClickedCheckDepth)
85 ON_BN_CLICKED(IDC_CHECK_FFONLY, OnBnClickedCheckFfonly)
86 ON_BN_CLICKED(IDC_CHECK_NOFF, OnBnClickedCheckFfonly)
87 END_MESSAGE_MAP()
89 BOOL CPullFetchDlg::OnInitDialog()
91 CHorizontalResizableStandAloneDialog::OnInitDialog();
92 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
94 AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);
95 AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);
97 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
98 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT);
100 AddAnchor(IDOK,BOTTOM_RIGHT);
101 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
102 AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,TOP_RIGHT);
103 AddAnchor(IDC_GROUP_OPTION,TOP_LEFT,TOP_RIGHT);
104 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);
105 AddAnchor(IDC_CHECK_PRUNE,BOTTOM_LEFT);
106 AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);
107 AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);
108 AddAnchor(IDHELP, BOTTOM_RIGHT);
110 AdjustControlSize(IDC_REMOTE_RD);
111 AdjustControlSize(IDC_OTHER_RD);
112 AdjustControlSize(IDC_CHECK_SQUASH);
113 AdjustControlSize(IDC_CHECK_NOCOMMIT);
114 AdjustControlSize(IDC_CHECK_DEPTH);
115 AdjustControlSize(IDC_CHECK_NOFF);
116 AdjustControlSize(IDC_CHECK_FFONLY);
117 AdjustControlSize(IDC_CHECK_FETCHTAGS);
118 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD);
119 AdjustControlSize(IDC_CHECK_REBASE);
120 AdjustControlSize(IDC_CHECK_PRUNE);
122 CString WorkingDir=g_Git.m_CurrentDir;
123 WorkingDir.Replace(_T(':'),_T('_'));
125 m_RemoteReg = CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
126 CString regkey;
127 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
128 m_regRebase=CRegDWORD(regkey,false);
129 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\ffonly"), WorkingDir, m_IsPull);
130 m_regFFonly = CRegDWORD(regkey, false);
131 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir,this->m_IsPull);
133 m_regAutoLoadPutty = CRegDWORD(regkey,this->m_bAutoLoad);
134 m_bAutoLoad = m_regAutoLoadPutty;
136 if(!CAppUtils::IsSSHPutty())
137 m_bAutoLoad = false;
139 if(m_bAllowRebase)
141 this->m_bRebase = m_regRebase;
143 else
145 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
146 this->m_bRebase = FALSE;
149 this->UpdateData(FALSE);
151 this->AddOthersToAnchor();
153 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
155 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
156 m_Remote.EnableWindow(TRUE);
157 m_Other.EnableWindow(FALSE);
158 if(!m_IsPull)
160 m_RemoteBranch.EnableWindow(FALSE);
161 GetDlgItem(IDC_BUTTON_BROWSE_REF)->EnableWindow(FALSE);
164 if(m_IsPull)
166 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
167 // check tags checkbox and make it a normal checkbox
168 m_bFetchTags = 1;
169 m_bFFonly = m_regFFonly;
170 UpdateData(FALSE);
171 ::SendMessage(GetDlgItem(IDC_CHECK_FETCHTAGS)->GetSafeHwnd(), BM_SETSTYLE, GetDlgItem(IDC_CHECK_FETCHTAGS)->GetStyle() & ~BS_AUTO3STATE | BS_AUTOCHECKBOX, 0);
172 OnBnClickedCheckFfonly();
174 else
176 this->GetDlgItem(IDC_GROUP_OPTION)->EnableWindow(FALSE);
177 this->GetDlgItem(IDC_CHECK_SQUASH)->EnableWindow(FALSE);
178 this->GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(FALSE);
179 this->GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(FALSE);
180 this->GetDlgItem(IDC_CHECK_NOCOMMIT)->EnableWindow(FALSE);
183 if (g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir))
184 this->GetDlgItem(IDC_CHECK_REBASE)->EnableWindow(FALSE);
186 CAutoRepository repo(g_Git.GetGitRepository());
187 if (git_repository_is_shallow(repo))
189 m_bDepth = TRUE;
190 UpdateData(FALSE);
192 else
194 GetDlgItem(IDC_CHECK_DEPTH)->ShowWindow(SW_HIDE);
195 GetDlgItem(IDC_EDIT_DEPTH)->ShowWindow(SW_HIDE);
197 OnBnClickedCheckDepth();
199 m_Other.SetCaseSensitive(TRUE);
200 m_Other.SetURLHistory(TRUE);
201 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
203 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
204 m_RemoteBranch.SetCurSel(0);
206 CString sWindowTitle;
207 if(m_IsPull)
208 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_PULL));
209 else
210 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH));
212 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
214 Refresh();
216 EnableSaveRestore(_T("PullFetchDlg"));
217 this->m_RemoteManage.SetURL(CString());
218 return TRUE;
221 void CPullFetchDlg::Refresh()
223 //Select pull-remote from current branch
224 CString currentBranch;
225 if (g_Git.GetCurrentBranchFromFile(g_Git.m_CurrentDir, currentBranch))
226 currentBranch.Empty();
228 CString pullRemote, pullBranch;
229 g_Git.GetRemoteTrackedBranch(currentBranch, pullRemote, pullBranch);
230 m_configPullRemote = pullRemote;
231 m_configPullBranch = pullBranch;
233 if (pullBranch.IsEmpty())
234 m_RemoteBranch.AddString(currentBranch);
235 else
236 m_RemoteBranch.AddString(pullBranch);
238 if(pullRemote.IsEmpty())
239 pullRemote = m_RemoteReg;
241 if (!m_PreSelectRemote.IsEmpty())
242 pullRemote = m_PreSelectRemote;
244 STRING_VECTOR list;
245 m_Remote.Reset();
246 int sel=0;
247 if(!g_Git.GetRemoteList(list))
249 if (!m_IsPull && list.size() > 1)
250 m_Remote.AddString(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)));
252 for (unsigned int i = 0; i < list.size(); ++i)
254 m_Remote.AddString(list[i]);
255 if (!m_bAllRemotes && list[i] == pullRemote)
256 sel = i + (!m_IsPull && list.size() > 1 ? 1 : 0);
259 m_Remote.SetCurSel(sel);
260 OnCbnSelchangeRemote();
262 // CPullFetchDlg message handlers
264 void CPullFetchDlg::OnCbnSelchangeRemote()
266 CString remote = m_Remote.GetString();
267 if (remote.IsEmpty() || remote == CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)))
269 GetDlgItem(IDC_STATIC_TAGOPT)->SetWindowText(_T(""));
270 GetDlgItem(IDC_STATIC_PRUNE)->SetWindowText(_T(""));
271 return;
274 CString key;
275 key.Format(_T("remote.%s.tagopt"), remote);
276 CString tagopt = g_Git.GetConfigValue(key);
277 if (tagopt == "--no-tags")
278 tagopt = CString(MAKEINTRESOURCE(IDS_NONE));
279 else if (tagopt == "--tags")
280 tagopt = CString(MAKEINTRESOURCE(CAppUtils::GetMsysgitVersion() < 0x01090000 ? IDS_FETCH_TAGS_ONLY : IDS_ALL));
281 else
282 tagopt = CString(MAKEINTRESOURCE(IDS_FETCH_REACHABLE));
283 CString value;
284 value.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT)), tagopt);
285 GetDlgItem(IDC_STATIC_TAGOPT)->SetWindowText(value);
287 CString prune;
288 if (CAppUtils::GetMsysgitVersion() >= 0x01080500)
290 key.Format(_T("remote.%s.prune"), remote);
291 prune = g_Git.GetConfigValue(key);
292 if (prune.IsEmpty())
293 prune = g_Git.GetConfigValue(_T("fetch.prune"));
295 if (!prune.IsEmpty())
297 CString value;
298 value.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT)), prune);
299 GetDlgItem(IDC_STATIC_PRUNE)->SetWindowText(value);
301 else
302 GetDlgItem(IDC_STATIC_PRUNE)->SetWindowText(_T(""));
305 void CPullFetchDlg::OnBnClickedRd()
307 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
309 m_Remote.EnableWindow(TRUE);
310 m_Other.EnableWindow(FALSE);
311 if(!m_IsPull)
312 m_RemoteBranch.EnableWindow(FALSE);
314 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
316 CString clippath = CAppUtils::GetClipboardLink(m_IsPull ? _T("git pull") : _T("git fetch"), 1);
317 if (clippath.IsEmpty())
318 m_Other.SetCurSel(0);
319 else
321 int argSeparator = clippath.Find(' ');
322 if (argSeparator > 1 && clippath.GetLength() > argSeparator + 2)
324 m_Other.SetWindowText(clippath.Left(argSeparator));
325 m_RemoteBranch.SetWindowText(clippath.Mid(argSeparator + 1));
327 else
328 m_Other.SetWindowText(clippath);
330 m_Remote.EnableWindow(FALSE);
331 m_Other.EnableWindow(TRUE);;
332 if(!m_IsPull)
333 m_RemoteBranch.EnableWindow(TRUE);
337 void CPullFetchDlg::OnBnClickedOk()
339 this->UpdateData();
340 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
342 m_RemoteURL=m_Remote.GetString();
343 m_bAllRemotes = (m_Remote.GetCurSel() == 0 && m_Remote.GetCount() > 1 && !m_IsPull);
344 if( !m_IsPull ||
345 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
346 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
347 //because otherwise git will not update the remote tracking branches.
348 m_RemoteBranchName.Empty();
349 else
350 m_RemoteBranchName=m_RemoteBranch.GetString();
352 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
354 m_Other.GetWindowTextW(m_RemoteURL);
355 m_RemoteBranchName=m_RemoteBranch.GetString();
357 // only store URL in history if it's value was used
358 m_Other.SaveHistory();
361 m_RemoteReg = m_Remote.GetString();
363 m_RemoteBranch.SaveHistory();
364 this->m_regRebase=this->m_bRebase;
365 m_regFFonly = m_bFFonly;
367 m_regAutoLoadPutty = m_bAutoLoad;
369 this->OnOK();
372 void CPullFetchDlg::OnStnClickedRemoteManage()
374 CAppUtils::LaunchRemoteSetting();
375 Refresh();
378 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
380 CString initialRef;
381 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
382 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
383 if(selectedRef.Left(13) != "refs/remotes/")
384 return;
386 selectedRef = selectedRef.Mid(13);
387 int ixSlash = selectedRef.Find('/');
389 CString remoteName = selectedRef.Left(ixSlash);
390 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
392 int ixFound = m_Remote.FindStringExact(0, remoteName);
393 if(ixFound >= 0)
394 m_Remote.SetCurSel(ixFound);
395 m_RemoteBranch.AddString(remoteBranch, 0);
397 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
400 void CPullFetchDlg::OnBnClickedCheckDepth()
402 UpdateData(TRUE);
403 GetDlgItem(IDC_EDIT_DEPTH)->EnableWindow(m_bDepth);
406 void CPullFetchDlg::OnBnClickedCheckFfonly()
408 UpdateData();
409 if (m_bNoFF)
411 m_bFFonly = FALSE;
412 GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(FALSE);
414 else
416 GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(TRUE);
418 if (m_bFFonly)
420 m_bNoFF = FALSE;
421 GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(FALSE);
423 else
425 GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(TRUE);
427 UpdateData(FALSE);