Correctly initialize m_bPrune
[TortoiseGit.git] / src / TortoiseProc / PullFetchDlg.cpp
blobcfc182da61c0395f72cecef10bbef1d14b6a7025
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 = 2;
45 m_bAllRemotes = FALSE;
46 m_bPrune = false;
49 CPullFetchDlg::~CPullFetchDlg()
53 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
55 CDialog::DoDataExchange(pDX);
56 DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);
57 DDX_Control(pDX, IDC_OTHER, this->m_Other);
58 DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);
59 DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);
60 DDX_Check(pDX,IDC_CHECK_NOFF, this->m_bNoFF);
61 DDX_Check(pDX,IDC_CHECK_SQUASH, this->m_bSquash);
62 DDX_Check(pDX,IDC_CHECK_NOCOMMIT, this->m_bNoCommit);
63 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);
64 DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);
65 DDX_Check(pDX,IDC_CHECK_PRUNE,m_bPrune);
66 DDX_Check(pDX, IDC_CHECK_FFONLY, m_bFFonly);
67 DDX_Check(pDX, IDC_CHECK_FETCHTAGS, m_bFetchTags);
71 BEGIN_MESSAGE_MAP(CPullFetchDlg, CHorizontalResizableStandAloneDialog)
72 ON_CBN_SELCHANGE(IDC_REMOTE_COMBO, &CPullFetchDlg::OnCbnSelchangeRemote)
73 ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)
74 ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)
75 ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)
76 ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)
77 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)
78 END_MESSAGE_MAP()
80 BOOL CPullFetchDlg::OnInitDialog()
82 CHorizontalResizableStandAloneDialog::OnInitDialog();
83 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
85 AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);
86 AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);
88 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
89 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT);
91 AddAnchor(IDOK,BOTTOM_RIGHT);
92 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
93 AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,TOP_RIGHT);
94 AddAnchor(IDC_GROUP_OPTION,TOP_LEFT,TOP_RIGHT);
95 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);
96 AddAnchor(IDC_CHECK_PRUNE,BOTTOM_LEFT);
97 AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);
98 AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);
99 AddAnchor(IDHELP, BOTTOM_RIGHT);
101 AdjustControlSize(IDC_REMOTE_RD);
102 AdjustControlSize(IDC_OTHER_RD);
103 AdjustControlSize(IDC_CHECK_SQUASH);
104 AdjustControlSize(IDC_CHECK_NOCOMMIT);
105 AdjustControlSize(IDC_CHECK_NOFF);
106 AdjustControlSize(IDC_CHECK_FFONLY);
107 AdjustControlSize(IDC_CHECK_FETCHTAGS);
108 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD);
109 AdjustControlSize(IDC_CHECK_REBASE);
110 AdjustControlSize(IDC_CHECK_PRUNE);
112 CString WorkingDir=g_Git.m_CurrentDir;
113 WorkingDir.Replace(_T(':'),_T('_'));
115 m_RemoteReg = CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
116 CString regkey;
117 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
118 m_regRebase=CRegDWORD(regkey,false);
119 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir,this->m_IsPull);
121 m_regAutoLoadPutty = CRegDWORD(regkey,this->m_bAutoLoad);
122 m_bAutoLoad = m_regAutoLoadPutty;
124 if(!CAppUtils::IsSSHPutty())
125 m_bAutoLoad = false;
127 if(m_bAllowRebase)
129 this->m_bRebase = m_regRebase;
131 else
133 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
134 this->m_bRebase = FALSE;
137 this->UpdateData(FALSE);
139 this->AddOthersToAnchor();
141 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
143 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
144 m_Remote.EnableWindow(TRUE);
145 m_Other.EnableWindow(FALSE);
146 if(!m_IsPull)
148 m_RemoteBranch.EnableWindow(FALSE);
149 GetDlgItem(IDC_BUTTON_BROWSE_REF)->EnableWindow(FALSE);
152 if(m_IsPull)
154 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
155 GetDlgItem(IDC_CHECK_PRUNE)->ShowWindow(SW_HIDE);
156 // check tags checkbox and make it a normal checkbox
157 m_bFetchTags = 1;
158 UpdateData(FALSE);
159 ::SendMessage(GetDlgItem(IDC_CHECK_FETCHTAGS)->GetSafeHwnd(), BM_SETSTYLE, GetDlgItem(IDC_CHECK_FETCHTAGS)->GetStyle() & ~BS_AUTO3STATE | BS_AUTOCHECKBOX, 0);
161 else
163 this->GetDlgItem(IDC_GROUP_OPTION)->EnableWindow(FALSE);
164 this->GetDlgItem(IDC_CHECK_SQUASH)->EnableWindow(FALSE);
165 this->GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(FALSE);
166 this->GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(FALSE);
167 this->GetDlgItem(IDC_CHECK_NOCOMMIT)->EnableWindow(FALSE);
170 if (g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir))
171 this->GetDlgItem(IDC_CHECK_REBASE)->EnableWindow(FALSE);
173 m_Other.SetURLHistory(TRUE);
174 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
175 CString clippath=CAppUtils::GetClipboardLink();
176 if(clippath.IsEmpty())
177 m_Other.SetCurSel(0);
178 else
179 m_Other.SetWindowText(clippath);
181 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
182 m_RemoteBranch.SetCurSel(0);
184 CString sWindowTitle;
185 if(m_IsPull)
186 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_PULL));
187 else
188 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH));
190 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
192 Refresh();
194 EnableSaveRestore(_T("PullFetchDlg"));
195 this->m_RemoteManage.SetURL(CString());
196 return TRUE;
199 void CPullFetchDlg::Refresh()
201 //Select pull-remote from current branch
202 CString currentBranch = g_Git.GetSymbolicRef();
203 CString configName;
204 configName.Format(L"branch.%s.remote", currentBranch);
205 CString pullRemote = this->m_configPullRemote = g_Git.GetConfigValue(configName);
207 //Select pull-branch from current branch
208 configName.Format(L"branch.%s.merge", currentBranch);
209 CString pullBranch = m_configPullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
210 if (pullBranch.IsEmpty())
211 m_RemoteBranch.AddString(currentBranch);
212 else
213 m_RemoteBranch.AddString(pullBranch);
215 if(pullRemote.IsEmpty())
216 pullRemote = m_RemoteReg;
218 if (!m_PreSelectRemote.IsEmpty())
219 pullRemote = m_PreSelectRemote;
221 STRING_VECTOR list;
222 int sel=0;
223 if (!m_IsPull)
224 list.push_back(_T("- all -"));
225 if(!g_Git.GetRemoteList(list))
227 if (!m_IsPull && list.size() <= 2)
228 list.erase(list.begin());
230 for(unsigned int i=0;i<list.size();i++)
232 m_Remote.AddString(list[i]);
233 if(list[i] == pullRemote)
234 sel = i;
237 m_Remote.SetCurSel(sel);
238 OnCbnSelchangeRemote();
240 // CPullFetchDlg message handlers
242 void CPullFetchDlg::OnCbnSelchangeRemote()
244 if (m_Remote.GetCurSel() == 0)
245 return;
247 CString remote = m_Remote.GetString();
248 CString key;
249 key.Format(_T("remote.%s.tagopt"), remote);
250 CString tagopt = g_Git.GetConfigValue(key);
251 if (tagopt == "--no-tags")
252 tagopt = CString(MAKEINTRESOURCE(IDS_NONE));
253 else if (tagopt == "--tags")
254 tagopt = CString(MAKEINTRESOURCE(IDS_ALL));
255 else
256 tagopt = CString(MAKEINTRESOURCE(IDS_FETCH_REACHABLE));
257 CString value;
258 value.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT)), tagopt);
259 GetDlgItem(IDC_STATIC_TAGOPT)->SetWindowText(value);
262 void CPullFetchDlg::OnBnClickedRd()
264 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
266 m_Remote.EnableWindow(TRUE);
267 m_Other.EnableWindow(FALSE);
268 if(!m_IsPull)
269 m_RemoteBranch.EnableWindow(FALSE);
271 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
273 m_Remote.EnableWindow(FALSE);
274 m_Other.EnableWindow(TRUE);;
275 if(!m_IsPull)
276 m_RemoteBranch.EnableWindow(TRUE);
280 void CPullFetchDlg::OnBnClickedOk()
282 this->UpdateData();
283 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
285 m_RemoteURL=m_Remote.GetString();
286 m_bAllRemotes = (m_Remote.GetCurSel() == 0 && m_Remote.GetCount() > 1 && !m_IsPull);
287 if( !m_IsPull ||
288 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
289 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
290 //because otherwise git will not update the remote tracking branches.
291 m_RemoteBranchName.Empty();
292 else
293 m_RemoteBranchName=m_RemoteBranch.GetString();
295 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
297 m_Other.GetWindowTextW(m_RemoteURL);
298 m_RemoteBranchName=m_RemoteBranch.GetString();
301 m_RemoteReg = m_Remote.GetString();
303 m_Other.SaveHistory();
304 m_RemoteBranch.SaveHistory();
305 this->m_regRebase=this->m_bRebase;
307 m_regAutoLoadPutty = m_bAutoLoad;
309 this->OnOK();
312 void CPullFetchDlg::OnStnClickedRemoteManage()
314 CAppUtils::LaunchRemoteSetting();
315 Refresh();
318 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
320 CString initialRef;
321 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
322 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
323 if(selectedRef.Left(13) != "refs/remotes/")
324 return;
326 selectedRef = selectedRef.Mid(13);
327 int ixSlash = selectedRef.Find('/');
329 CString remoteName = selectedRef.Left(ixSlash);
330 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
332 int ixFound = m_Remote.FindStringExact(0, remoteName);
333 if(ixFound >= 0)
334 m_Remote.SetCurSel(ixFound);
335 m_RemoteBranch.AddString(remoteBranch, 0);
337 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);