Fixed issue #1264: TortoiseProc might crash if commands are executed w/o a working...
[TortoiseGit.git] / src / TortoiseProc / PullFetchDlg.cpp
blob9a89851433f06a32da701686ba9cf114fa73895a
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;
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 AdjustControlSize(IDC_REMOTE_RD);
99 AdjustControlSize(IDC_OTHER_RD);
100 AdjustControlSize(IDC_CHECK_SQUASH);
101 AdjustControlSize(IDC_CHECK_NOCOMMIT);
102 AdjustControlSize(IDC_CHECK_NOFF);
103 AdjustControlSize(IDC_CHECK_FFONLY);
104 AdjustControlSize(IDC_CHECK_FETCHTAGS);
105 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD);
106 AdjustControlSize(IDC_CHECK_REBASE);
107 AdjustControlSize(IDC_CHECK_PRUNE);
109 CString WorkingDir=g_Git.m_CurrentDir;
110 WorkingDir.Replace(_T(':'),_T('_'));
112 m_RemoteReg = CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
113 CString regkey;
114 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
115 m_regRebase=CRegDWORD(regkey,false);
116 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir,this->m_IsPull);
118 m_regAutoLoadPutty = CRegDWORD(regkey,this->m_bAutoLoad);
119 m_bAutoLoad = m_regAutoLoadPutty;
121 if(!CAppUtils::IsSSHPutty())
122 m_bAutoLoad = false;
124 if(m_bAllowRebase)
126 this->m_bRebase = m_regRebase;
128 else
130 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
131 this->m_bRebase = FALSE;
134 this->UpdateData(FALSE);
136 this->AddOthersToAnchor();
138 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
140 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
141 m_Remote.EnableWindow(TRUE);
142 m_Other.EnableWindow(FALSE);
143 if(!m_IsPull)
144 m_RemoteBranch.EnableWindow(FALSE);
146 if(m_IsPull)
148 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
149 GetDlgItem(IDC_CHECK_PRUNE)->ShowWindow(SW_HIDE);
150 GetDlgItem(IDC_CHECK_FETCHTAGS)->EnableWindow(FALSE);
152 else
154 this->GetDlgItem(IDC_GROUP_OPTION)->EnableWindow(FALSE);
155 this->GetDlgItem(IDC_CHECK_SQUASH)->EnableWindow(FALSE);
156 this->GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(FALSE);
157 this->GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(FALSE);
158 this->GetDlgItem(IDC_CHECK_NOCOMMIT)->EnableWindow(FALSE);
161 if (g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir))
162 this->GetDlgItem(IDC_CHECK_REBASE)->EnableWindow(FALSE);
164 m_Other.SetURLHistory(TRUE);
165 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
166 CString clippath=CAppUtils::GetClipboardLink();
167 if(clippath.IsEmpty())
168 m_Other.SetCurSel(0);
169 else
170 m_Other.SetWindowText(clippath);
172 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
173 m_RemoteBranch.SetCurSel(0);
175 CString sWindowTitle;
176 if(m_IsPull)
177 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_PULL));
178 else
179 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH));
181 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
183 Refresh();
185 EnableSaveRestore(_T("PullFetchDlg"));
186 this->m_RemoteManage.SetURL(CString());
187 return TRUE;
190 void CPullFetchDlg::Refresh()
192 //Select pull-remote from current branch
193 CString currentBranch = g_Git.GetSymbolicRef();
194 CString configName;
195 configName.Format(L"branch.%s.remote", currentBranch);
196 CString pullRemote = this->m_configPullRemote = g_Git.GetConfigValue(configName);
198 //Select pull-branch from current branch
199 configName.Format(L"branch.%s.merge", currentBranch);
200 CString pullBranch = m_configPullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
201 if (pullBranch.IsEmpty())
202 m_RemoteBranch.AddString(currentBranch);
203 else
204 m_RemoteBranch.AddString(pullBranch);
206 if(pullRemote.IsEmpty())
207 pullRemote = m_RemoteReg;
209 if (!m_PreSelectRemote.IsEmpty())
210 pullRemote = m_PreSelectRemote;
212 STRING_VECTOR list;
213 int sel=0;
214 if(!g_Git.GetRemoteList(list))
216 for(unsigned int i=0;i<list.size();i++)
218 m_Remote.AddString(list[i]);
219 if(list[i] == pullRemote)
220 sel = i;
223 m_Remote.SetCurSel(sel);
225 // CPullFetchDlg message handlers
227 void CPullFetchDlg::OnBnClickedRd()
229 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
231 m_Remote.EnableWindow(TRUE);
232 m_Other.EnableWindow(FALSE);
233 if(!m_IsPull)
234 m_RemoteBranch.EnableWindow(FALSE);
236 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
238 m_Remote.EnableWindow(FALSE);
239 m_Other.EnableWindow(TRUE);;
240 if(!m_IsPull)
241 m_RemoteBranch.EnableWindow(TRUE);
245 void CPullFetchDlg::OnBnClickedOk()
247 this->UpdateData();
248 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
250 m_RemoteURL=m_Remote.GetString();
251 if( !m_IsPull ||
252 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
253 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
254 //because otherwise git will not update the remote tracking branches.
255 m_RemoteBranchName.Empty();
256 else
257 m_RemoteBranchName=m_RemoteBranch.GetString();
259 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
261 m_Other.GetWindowTextW(m_RemoteURL);
262 m_RemoteBranchName=m_RemoteBranch.GetString();
265 m_RemoteReg = m_Remote.GetString();
267 m_Other.SaveHistory();
268 m_RemoteBranch.SaveHistory();
269 this->m_regRebase=this->m_bRebase;
271 m_regAutoLoadPutty = m_bAutoLoad;
273 this->OnOK();
276 void CPullFetchDlg::OnStnClickedRemoteManage()
278 CAppUtils::LaunchRemoteSetting();
279 Refresh();
282 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
284 CString initialRef;
285 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
286 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
287 if(selectedRef.Left(13) != "refs/remotes/")
288 return;
290 selectedRef = selectedRef.Mid(13);
291 int ixSlash = selectedRef.Find('/');
293 CString remoteName = selectedRef.Left(ixSlash);
294 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
296 int ixFound = m_Remote.FindStringExact(0, remoteName);
297 if(ixFound >= 0)
298 m_Remote.SetCurSel(ixFound);
299 m_RemoteBranch.AddString(remoteBranch);
301 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);