Fixed blame crash at XP system
[TortoiseGit.git] / src / TortoiseProc / PullFetchDlg.cpp
blob7bc08e05dc16c992a4786c13be89757e52565996
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, CResizableStandAloneDialog)
33 CPullFetchDlg::CPullFetchDlg(CWnd* pParent /*=NULL*/)
34 : CResizableStandAloneDialog(CPullFetchDlg::IDD, pParent)
36 m_IsPull=TRUE;
37 m_bAutoLoad = CAppUtils::IsSSHPutty();
38 m_bAutoLoadEnable=CAppUtils::IsSSHPutty();;
39 m_regRebase = false;
42 CPullFetchDlg::~CPullFetchDlg()
46 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
48 CDialog::DoDataExchange(pDX);
49 DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);
50 DDX_Control(pDX, IDC_OTHER, this->m_Other);
51 DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);
52 DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);
53 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);
54 DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);
55 DDX_Check(pDX,IDC_CHECK_PRUNE,m_bPrune);
59 BEGIN_MESSAGE_MAP(CPullFetchDlg,CResizableStandAloneDialog )
60 ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)
61 ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)
62 ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)
63 ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)
64 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)
65 END_MESSAGE_MAP()
67 BOOL CPullFetchDlg::OnInitDialog()
69 CResizableStandAloneDialog::OnInitDialog();
70 AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);
71 AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);
73 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
74 AddAnchor(IDC_BUTTON_BROWSE_REF,TOP_RIGHT);
76 AddAnchor(IDOK,BOTTOM_RIGHT);
77 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
78 AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,BOTTOM_RIGHT);
79 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);
80 AddAnchor(IDC_CHECK_PRUNE,BOTTOM_LEFT);
81 AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);
82 AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);
83 AddAnchor(IDHELP, BOTTOM_RIGHT);
85 CString WorkingDir=g_Git.m_CurrentDir;
86 WorkingDir.Replace(_T(':'),_T('_'));
88 m_RemoteReg = CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
89 CString regkey;
90 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
91 m_regRebase=CRegDWORD(regkey,false);
92 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir,this->m_IsPull);
94 m_regAutoLoadPutty = CRegDWORD(regkey,this->m_bAutoLoad);
95 m_bAutoLoad = m_regAutoLoadPutty;
97 if(!CAppUtils::IsSSHPutty())
98 m_bAutoLoad = false;
100 if(m_bAllowRebase)
102 this->m_bRebase = m_regRebase;
104 else
106 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
107 this->m_bRebase = FALSE;
110 this->UpdateData(FALSE);
112 this->AddOthersToAnchor();
114 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
116 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
117 m_Remote.EnableWindow(TRUE);
118 m_Other.EnableWindow(FALSE);
119 if(!m_IsPull)
120 m_RemoteBranch.EnableWindow(FALSE);
122 if(m_IsPull) {
123 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
124 GetDlgItem(IDC_CHECK_PRUNE)->ShowWindow(SW_HIDE);
127 m_Other.SetURLHistory(TRUE);
128 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
129 CString clippath=CAppUtils::GetClipboardLink();
130 if(clippath.IsEmpty())
131 m_Other.SetCurSel(0);
132 else
133 m_Other.SetWindowText(clippath);
135 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
136 m_RemoteBranch.SetCurSel(0);
138 if(m_IsPull)
139 this->SetWindowTextW(CString(_T("Pull - ")) + g_Git.m_CurrentDir);
140 else
141 this->SetWindowTextW(CString(_T("Fetch - ")) + g_Git.m_CurrentDir);
143 Refresh();
145 EnableSaveRestore(_T("PullFetchDlg"));
146 this->m_RemoteManage.SetURL(CString());
147 return TRUE;
150 void CPullFetchDlg::Refresh()
152 //Select pull-remote from current branch
153 CString currentBranch = g_Git.GetSymbolicRef();
154 CString configName;
155 configName.Format(L"branch.%s.remote", currentBranch);
156 CString pullRemote = this->m_configPullRemote = g_Git.GetConfigValue(configName);
158 //Select pull-branch from current branch
159 configName.Format(L"branch.%s.merge", currentBranch);
160 CString pullBranch = m_configPullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
161 m_RemoteBranch.AddString(pullBranch);
163 if(pullRemote.IsEmpty())
164 pullRemote = m_RemoteReg;
166 if (!m_PreSelectRemote.IsEmpty())
167 pullRemote = m_PreSelectRemote;
169 STRING_VECTOR list;
170 int sel=0;
171 if(!g_Git.GetRemoteList(list))
173 for(unsigned int i=0;i<list.size();i++)
175 m_Remote.AddString(list[i]);
176 if(list[i] == pullRemote)
177 sel = i;
180 m_Remote.SetCurSel(sel);
182 // CPullFetchDlg message handlers
184 void CPullFetchDlg::OnBnClickedRd()
186 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
188 m_Remote.EnableWindow(TRUE);
189 m_Other.EnableWindow(FALSE);
190 if(!m_IsPull)
191 m_RemoteBranch.EnableWindow(FALSE);
193 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
195 m_Remote.EnableWindow(FALSE);
196 m_Other.EnableWindow(TRUE);;
197 if(!m_IsPull)
198 m_RemoteBranch.EnableWindow(TRUE);
202 void CPullFetchDlg::OnBnClickedOk()
204 this->UpdateData();
205 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
207 m_RemoteURL=m_Remote.GetString();
208 if( !m_IsPull ||
209 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
210 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
211 //because otherwise git will not update the remote tracking branches.
212 m_RemoteBranchName.Empty();
213 else
214 m_RemoteBranchName=m_RemoteBranch.GetString();
216 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
218 m_Other.GetWindowTextW(m_RemoteURL);
219 m_RemoteBranchName=m_RemoteBranch.GetString();
222 m_RemoteReg = m_Remote.GetString();
224 m_Other.SaveHistory();
225 m_RemoteBranch.SaveHistory();
226 this->m_regRebase=this->m_bRebase;
228 m_regAutoLoadPutty = m_bAutoLoad;
230 this->OnOK();
233 void CPullFetchDlg::OnStnClickedRemoteManage()
235 CAppUtils::LaunchRemoteSetting();
236 Refresh();
239 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
241 CString initialRef;
242 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
243 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
244 if(selectedRef.Left(13) != "refs/remotes/")
245 return;
247 selectedRef = selectedRef.Mid(13);
248 int ixSlash = selectedRef.Find('/');
250 CString remoteName = selectedRef.Left(ixSlash);
251 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
253 int ixFound = m_Remote.FindStringExact(0, remoteName);
254 if(ixFound >= 0)
255 m_Remote.SetCurSel(ixFound);
256 m_RemoteBranch.AddString(remoteBranch);
258 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);