Merge branch 'restructure-tree'
[TortoiseGit.git] / src / TortoiseProc / PullFetchDlg.cpp
blobda831dc637431513cee20188c25f63adfd4bd936
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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;
45 CPullFetchDlg::~CPullFetchDlg()
49 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
51 CDialog::DoDataExchange(pDX);
52 DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);
53 DDX_Control(pDX, IDC_OTHER, this->m_Other);
54 DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);
55 DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);
56 DDX_Check(pDX,IDC_CHECK_NOFF, this->m_bNoFF);
57 DDX_Check(pDX,IDC_CHECK_SQUASH, this->m_bSquash);
58 DDX_Check(pDX,IDC_CHECK_NOCOMMIT, this->m_bNoCommit);
59 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);
60 DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);
61 DDX_Check(pDX,IDC_CHECK_PRUNE,m_bPrune);
65 BEGIN_MESSAGE_MAP(CPullFetchDlg, CHorizontalResizableStandAloneDialog)
66 ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)
67 ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)
68 ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)
69 ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)
70 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)
71 END_MESSAGE_MAP()
73 BOOL CPullFetchDlg::OnInitDialog()
75 CHorizontalResizableStandAloneDialog::OnInitDialog();
76 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
78 AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);
79 AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);
81 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
82 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT);
84 AddAnchor(IDOK,BOTTOM_RIGHT);
85 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
86 AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,TOP_RIGHT);
87 AddAnchor(IDC_GROUP_OPTION,TOP_LEFT,TOP_RIGHT);
88 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);
89 AddAnchor(IDC_CHECK_PRUNE,BOTTOM_LEFT);
90 AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);
91 AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);
92 AddAnchor(IDHELP, BOTTOM_RIGHT);
94 CString WorkingDir=g_Git.m_CurrentDir;
95 WorkingDir.Replace(_T(':'),_T('_'));
97 m_RemoteReg = CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
98 CString regkey;
99 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
100 m_regRebase=CRegDWORD(regkey,false);
101 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir,this->m_IsPull);
103 m_regAutoLoadPutty = CRegDWORD(regkey,this->m_bAutoLoad);
104 m_bAutoLoad = m_regAutoLoadPutty;
106 if(!CAppUtils::IsSSHPutty())
107 m_bAutoLoad = false;
109 if(m_bAllowRebase)
111 this->m_bRebase = m_regRebase;
113 else
115 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
116 this->m_bRebase = FALSE;
119 this->UpdateData(FALSE);
121 this->AddOthersToAnchor();
123 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
125 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
126 m_Remote.EnableWindow(TRUE);
127 m_Other.EnableWindow(FALSE);
128 if(!m_IsPull)
129 m_RemoteBranch.EnableWindow(FALSE);
131 if(m_IsPull) {
132 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
133 GetDlgItem(IDC_CHECK_PRUNE)->ShowWindow(SW_HIDE);
134 } else {
135 this->GetDlgItem(IDC_GROUP_OPTION)->EnableWindow(FALSE);
136 this->GetDlgItem(IDC_CHECK_SQUASH)->EnableWindow(FALSE);
137 this->GetDlgItem(IDC_CHECK_NOFF)->EnableWindow(FALSE);
138 this->GetDlgItem(IDC_CHECK_NOCOMMIT)->EnableWindow(FALSE);
141 m_Other.SetURLHistory(TRUE);
142 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
143 CString clippath=CAppUtils::GetClipboardLink();
144 if(clippath.IsEmpty())
145 m_Other.SetCurSel(0);
146 else
147 m_Other.SetWindowText(clippath);
149 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
150 m_RemoteBranch.SetCurSel(0);
152 if(m_IsPull)
153 this->SetWindowTextW(CString(_T("Pull - ")) + g_Git.m_CurrentDir);
154 else
155 this->SetWindowTextW(CString(_T("Fetch - ")) + g_Git.m_CurrentDir);
157 Refresh();
159 EnableSaveRestore(_T("PullFetchDlg"));
160 this->m_RemoteManage.SetURL(CString());
161 return TRUE;
164 void CPullFetchDlg::Refresh()
166 //Select pull-remote from current branch
167 CString currentBranch = g_Git.GetSymbolicRef();
168 CString configName;
169 configName.Format(L"branch.%s.remote", currentBranch);
170 CString pullRemote = this->m_configPullRemote = g_Git.GetConfigValue(configName);
172 //Select pull-branch from current branch
173 configName.Format(L"branch.%s.merge", currentBranch);
174 CString pullBranch = m_configPullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
175 m_RemoteBranch.AddString(pullBranch);
177 if(pullRemote.IsEmpty())
178 pullRemote = m_RemoteReg;
180 if (!m_PreSelectRemote.IsEmpty())
181 pullRemote = m_PreSelectRemote;
183 STRING_VECTOR list;
184 int sel=0;
185 if(!g_Git.GetRemoteList(list))
187 for(unsigned int i=0;i<list.size();i++)
189 m_Remote.AddString(list[i]);
190 if(list[i] == pullRemote)
191 sel = i;
194 m_Remote.SetCurSel(sel);
196 // CPullFetchDlg message handlers
198 void CPullFetchDlg::OnBnClickedRd()
200 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
202 m_Remote.EnableWindow(TRUE);
203 m_Other.EnableWindow(FALSE);
204 if(!m_IsPull)
205 m_RemoteBranch.EnableWindow(FALSE);
207 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
209 m_Remote.EnableWindow(FALSE);
210 m_Other.EnableWindow(TRUE);;
211 if(!m_IsPull)
212 m_RemoteBranch.EnableWindow(TRUE);
216 void CPullFetchDlg::OnBnClickedOk()
218 this->UpdateData();
219 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
221 m_RemoteURL=m_Remote.GetString();
222 if( !m_IsPull ||
223 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
224 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
225 //because otherwise git will not update the remote tracking branches.
226 m_RemoteBranchName.Empty();
227 else
228 m_RemoteBranchName=m_RemoteBranch.GetString();
230 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
232 m_Other.GetWindowTextW(m_RemoteURL);
233 m_RemoteBranchName=m_RemoteBranch.GetString();
236 m_RemoteReg = m_Remote.GetString();
238 m_Other.SaveHistory();
239 m_RemoteBranch.SaveHistory();
240 this->m_regRebase=this->m_bRebase;
242 m_regAutoLoadPutty = m_bAutoLoad;
244 this->OnOK();
247 void CPullFetchDlg::OnStnClickedRemoteManage()
249 CAppUtils::LaunchRemoteSetting();
250 Refresh();
253 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
255 CString initialRef;
256 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
257 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
258 if(selectedRef.Left(13) != "refs/remotes/")
259 return;
261 selectedRef = selectedRef.Mid(13);
262 int ixSlash = selectedRef.Find('/');
264 CString remoteName = selectedRef.Left(ixSlash);
265 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
267 int ixFound = m_Remote.FindStringExact(0, remoteName);
268 if(ixFound >= 0)
269 m_Remote.SetCurSel(ixFound);
270 m_RemoteBranch.AddString(remoteBranch);
272 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);