Fixed issue #1405: Cannot show branch description in Browse Reference Dialog with...
[TortoiseGit.git] / src / TortoiseProc / PullFetchDlg.cpp
bloba7db3fa6e10786e97f5608cf4a1b71ea00d2b145
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;
48 CPullFetchDlg::~CPullFetchDlg()
52 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
54 CDialog::DoDataExchange(pDX);
55 DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);
56 DDX_Control(pDX, IDC_OTHER, this->m_Other);
57 DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);
58 DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);
59 DDX_Check(pDX,IDC_CHECK_NOFF, this->m_bNoFF);
60 DDX_Check(pDX,IDC_CHECK_SQUASH, this->m_bSquash);
61 DDX_Check(pDX,IDC_CHECK_NOCOMMIT, this->m_bNoCommit);
62 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);
63 DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);
64 DDX_Check(pDX,IDC_CHECK_PRUNE,m_bPrune);
65 DDX_Check(pDX, IDC_CHECK_FFONLY, m_bFFonly);
66 DDX_Check(pDX, IDC_CHECK_FETCHTAGS, m_bFetchTags);
70 BEGIN_MESSAGE_MAP(CPullFetchDlg, CHorizontalResizableStandAloneDialog)
71 ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)
72 ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)
73 ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)
74 ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)
75 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)
76 END_MESSAGE_MAP()
78 BOOL CPullFetchDlg::OnInitDialog()
80 CHorizontalResizableStandAloneDialog::OnInitDialog();
81 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
83 AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);
84 AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);
86 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
87 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT);
89 AddAnchor(IDOK,BOTTOM_RIGHT);
90 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
91 AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,TOP_RIGHT);
92 AddAnchor(IDC_GROUP_OPTION,TOP_LEFT,TOP_RIGHT);
93 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);
94 AddAnchor(IDC_CHECK_PRUNE,BOTTOM_LEFT);
95 AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);
96 AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);
97 AddAnchor(IDHELP, BOTTOM_RIGHT);
99 AdjustControlSize(IDC_REMOTE_RD);
100 AdjustControlSize(IDC_OTHER_RD);
101 AdjustControlSize(IDC_CHECK_SQUASH);
102 AdjustControlSize(IDC_CHECK_NOCOMMIT);
103 AdjustControlSize(IDC_CHECK_NOFF);
104 AdjustControlSize(IDC_CHECK_FFONLY);
105 AdjustControlSize(IDC_CHECK_FETCHTAGS);
106 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD);
107 AdjustControlSize(IDC_CHECK_REBASE);
108 AdjustControlSize(IDC_CHECK_PRUNE);
110 CString WorkingDir=g_Git.m_CurrentDir;
111 WorkingDir.Replace(_T(':'),_T('_'));
113 m_RemoteReg = CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
114 CString regkey;
115 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
116 m_regRebase=CRegDWORD(regkey,false);
117 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir,this->m_IsPull);
119 m_regAutoLoadPutty = CRegDWORD(regkey,this->m_bAutoLoad);
120 m_bAutoLoad = m_regAutoLoadPutty;
122 if(!CAppUtils::IsSSHPutty())
123 m_bAutoLoad = false;
125 if(m_bAllowRebase)
127 this->m_bRebase = m_regRebase;
129 else
131 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
132 this->m_bRebase = FALSE;
135 this->UpdateData(FALSE);
137 this->AddOthersToAnchor();
139 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
141 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
142 m_Remote.EnableWindow(TRUE);
143 m_Other.EnableWindow(FALSE);
144 if(!m_IsPull)
145 m_RemoteBranch.EnableWindow(FALSE);
147 if(m_IsPull)
149 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
150 GetDlgItem(IDC_CHECK_PRUNE)->ShowWindow(SW_HIDE);
151 // check tags checkbox and make it a normal checkbox
152 m_bFetchTags = 1;
153 UpdateData(FALSE);
154 ::SendMessage(GetDlgItem(IDC_CHECK_FETCHTAGS)->GetSafeHwnd(), BM_SETSTYLE, GetDlgItem(IDC_CHECK_FETCHTAGS)->GetStyle() & ~BS_AUTO3STATE | BS_AUTOCHECKBOX, 0);
156 else
158 this->GetDlgItem(IDC_GROUP_OPTION)->EnableWindow(FALSE);
159 this->GetDlgItem(IDC_CHECK_SQUASH)->EnableWindow(FALSE);
160 this->GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(FALSE);
161 this->GetDlgItem(IDC_CHECK_FFONLY)->EnableWindow(FALSE);
162 this->GetDlgItem(IDC_CHECK_NOCOMMIT)->EnableWindow(FALSE);
165 if (g_GitAdminDir.IsBareRepo(g_Git.m_CurrentDir))
166 this->GetDlgItem(IDC_CHECK_REBASE)->EnableWindow(FALSE);
168 m_Other.SetURLHistory(TRUE);
169 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
170 CString clippath=CAppUtils::GetClipboardLink();
171 if(clippath.IsEmpty())
172 m_Other.SetCurSel(0);
173 else
174 m_Other.SetWindowText(clippath);
176 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
177 m_RemoteBranch.SetCurSel(0);
179 CString sWindowTitle;
180 if(m_IsPull)
181 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_PULL));
182 else
183 sWindowTitle = CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH));
185 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
187 Refresh();
189 EnableSaveRestore(_T("PullFetchDlg"));
190 this->m_RemoteManage.SetURL(CString());
191 return TRUE;
194 void CPullFetchDlg::Refresh()
196 //Select pull-remote from current branch
197 CString currentBranch = g_Git.GetSymbolicRef();
198 CString configName;
199 configName.Format(L"branch.%s.remote", currentBranch);
200 CString pullRemote = this->m_configPullRemote = g_Git.GetConfigValue(configName);
202 //Select pull-branch from current branch
203 configName.Format(L"branch.%s.merge", currentBranch);
204 CString pullBranch = m_configPullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
205 if (pullBranch.IsEmpty())
206 m_RemoteBranch.AddString(currentBranch);
207 else
208 m_RemoteBranch.AddString(pullBranch);
210 if(pullRemote.IsEmpty())
211 pullRemote = m_RemoteReg;
213 if (!m_PreSelectRemote.IsEmpty())
214 pullRemote = m_PreSelectRemote;
216 STRING_VECTOR list;
217 int sel=0;
218 if (!m_IsPull)
219 list.push_back(_T("- all -"));
220 if(!g_Git.GetRemoteList(list))
222 if (!m_IsPull && list.size() <= 2)
223 list.erase(list.begin());
225 for(unsigned int i=0;i<list.size();i++)
227 m_Remote.AddString(list[i]);
228 if(list[i] == pullRemote)
229 sel = i;
232 m_Remote.SetCurSel(sel);
234 // CPullFetchDlg message handlers
236 void CPullFetchDlg::OnBnClickedRd()
238 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
240 m_Remote.EnableWindow(TRUE);
241 m_Other.EnableWindow(FALSE);
242 if(!m_IsPull)
243 m_RemoteBranch.EnableWindow(FALSE);
245 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
247 m_Remote.EnableWindow(FALSE);
248 m_Other.EnableWindow(TRUE);;
249 if(!m_IsPull)
250 m_RemoteBranch.EnableWindow(TRUE);
254 void CPullFetchDlg::OnBnClickedOk()
256 this->UpdateData();
257 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
259 m_RemoteURL=m_Remote.GetString();
260 m_bAllRemotes = (m_Remote.GetCurSel() == 0 && m_Remote.GetCount() > 1 && !m_IsPull);
261 if( !m_IsPull ||
262 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
263 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
264 //because otherwise git will not update the remote tracking branches.
265 m_RemoteBranchName.Empty();
266 else
267 m_RemoteBranchName=m_RemoteBranch.GetString();
269 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
271 m_Other.GetWindowTextW(m_RemoteURL);
272 m_RemoteBranchName=m_RemoteBranch.GetString();
275 m_RemoteReg = m_Remote.GetString();
277 m_Other.SaveHistory();
278 m_RemoteBranch.SaveHistory();
279 this->m_regRebase=this->m_bRebase;
281 m_regAutoLoadPutty = m_bAutoLoad;
283 this->OnOK();
286 void CPullFetchDlg::OnStnClickedRemoteManage()
288 CAppUtils::LaunchRemoteSetting();
289 Refresh();
292 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
294 CString initialRef;
295 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
296 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
297 if(selectedRef.Left(13) != "refs/remotes/")
298 return;
300 selectedRef = selectedRef.Mid(13);
301 int ixSlash = selectedRef.Find('/');
303 CString remoteName = selectedRef.Left(ixSlash);
304 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
306 int ixFound = m_Remote.FindStringExact(0, remoteName);
307 if(ixFound >= 0)
308 m_Remote.SetCurSel(ixFound);
309 m_RemoteBranch.AddString(remoteBranch, 0);
311 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);