1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2014 - 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
24 #include "TortoiseProc.h"
25 #include "PullFetchDlg.h"
28 #include "BrowseRefsDlg.h"
29 // CPullFetchDlg dialog
31 IMPLEMENT_DYNAMIC(CPullFetchDlg
, CHorizontalResizableStandAloneDialog
)
33 CPullFetchDlg::CPullFetchDlg(CWnd
* pParent
/*=NULL*/)
34 : CHorizontalResizableStandAloneDialog(CPullFetchDlg::IDD
, pParent
)
37 m_bAllowRebase
= false;
38 m_bAutoLoad
= CAppUtils::IsSSHPutty();
39 m_bAutoLoadEnable
=CAppUtils::IsSSHPutty();;
49 m_bAllRemotes
= FALSE
;
50 m_bPrune
= CAppUtils::GetMsysgitVersion() >= 0x01080500 ? 2 : FALSE
;
53 CPullFetchDlg::~CPullFetchDlg()
57 void CPullFetchDlg::DoDataExchange(CDataExchange
* pDX
)
59 CDialog::DoDataExchange(pDX
);
60 DDX_Control(pDX
, IDC_REMOTE_COMBO
, this->m_Remote
);
61 DDX_Control(pDX
, IDC_OTHER
, this->m_Other
);
62 DDX_Control(pDX
, IDC_REMOTE_BRANCH
, this->m_RemoteBranch
);
63 DDX_Control(pDX
,IDC_REMOTE_MANAGE
, this->m_RemoteManage
);
64 DDX_Check(pDX
,IDC_CHECK_NOFF
, this->m_bNoFF
);
65 DDX_Check(pDX
,IDC_CHECK_SQUASH
, this->m_bSquash
);
66 DDX_Check(pDX
,IDC_CHECK_NOCOMMIT
, this->m_bNoCommit
);
67 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
,m_bAutoLoad
);
68 DDX_Check(pDX
,IDC_CHECK_REBASE
,m_bRebase
);
69 DDX_Check(pDX
,IDC_CHECK_PRUNE
,m_bPrune
);
70 DDX_Check(pDX
, IDC_CHECK_DEPTH
, m_bDepth
);
71 DDX_Text(pDX
, IDC_EDIT_DEPTH
, m_nDepth
);
72 DDX_Check(pDX
, IDC_CHECK_FFONLY
, m_bFFonly
);
73 DDX_Check(pDX
, IDC_CHECK_FETCHTAGS
, m_bFetchTags
);
77 BEGIN_MESSAGE_MAP(CPullFetchDlg
, CHorizontalResizableStandAloneDialog
)
78 ON_CBN_SELCHANGE(IDC_REMOTE_COMBO
, &CPullFetchDlg::OnCbnSelchangeRemote
)
79 ON_BN_CLICKED(IDC_REMOTE_RD
, &CPullFetchDlg::OnBnClickedRd
)
80 ON_BN_CLICKED(IDC_OTHER_RD
, &CPullFetchDlg::OnBnClickedRd
)
81 ON_BN_CLICKED(IDOK
, &CPullFetchDlg::OnBnClickedOk
)
82 ON_STN_CLICKED(IDC_REMOTE_MANAGE
, &CPullFetchDlg::OnStnClickedRemoteManage
)
83 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF
, &CPullFetchDlg::OnBnClickedButtonBrowseRef
)
84 ON_BN_CLICKED(IDC_CHECK_DEPTH
, OnBnClickedCheckDepth
)
85 ON_BN_CLICKED(IDC_CHECK_FFONLY
, OnBnClickedCheckFfonly
)
86 ON_BN_CLICKED(IDC_CHECK_NOFF
, OnBnClickedCheckFfonly
)
89 BOOL
CPullFetchDlg::OnInitDialog()
91 CHorizontalResizableStandAloneDialog::OnInitDialog();
92 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
94 AddAnchor(IDC_REMOTE_COMBO
, TOP_LEFT
, TOP_RIGHT
);
95 AddAnchor(IDC_OTHER
, TOP_LEFT
,TOP_RIGHT
);
97 AddAnchor(IDC_REMOTE_BRANCH
, TOP_LEFT
,TOP_RIGHT
);
98 AddAnchor(IDC_BUTTON_BROWSE_REF
,TOP_RIGHT
);
100 AddAnchor(IDOK
,BOTTOM_RIGHT
);
101 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
102 AddAnchor(IDC_GROUPT_REMOTE
,TOP_LEFT
,TOP_RIGHT
);
103 AddAnchor(IDC_GROUP_OPTION
,TOP_LEFT
,TOP_RIGHT
);
104 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,BOTTOM_LEFT
);
105 AddAnchor(IDC_CHECK_PRUNE
,BOTTOM_LEFT
);
106 AddAnchor(IDC_CHECK_REBASE
,BOTTOM_LEFT
);
107 AddAnchor(IDC_REMOTE_MANAGE
,BOTTOM_LEFT
);
108 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
110 AdjustControlSize(IDC_REMOTE_RD
);
111 AdjustControlSize(IDC_OTHER_RD
);
112 AdjustControlSize(IDC_CHECK_SQUASH
);
113 AdjustControlSize(IDC_CHECK_NOCOMMIT
);
114 AdjustControlSize(IDC_CHECK_DEPTH
);
115 AdjustControlSize(IDC_CHECK_NOFF
);
116 AdjustControlSize(IDC_CHECK_FFONLY
);
117 AdjustControlSize(IDC_CHECK_FETCHTAGS
);
118 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD
);
119 AdjustControlSize(IDC_CHECK_REBASE
);
120 AdjustControlSize(IDC_CHECK_PRUNE
);
122 CString WorkingDir
=g_Git
.m_CurrentDir
;
123 WorkingDir
.Replace(_T(':'),_T('_'));
125 m_RemoteReg
= CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir
));
127 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir
,this->m_IsPull
);
128 m_regRebase
=CRegDWORD(regkey
,false);
129 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\ffonly"), WorkingDir
, m_IsPull
);
130 m_regFFonly
= CRegDWORD(regkey
, false);
131 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir
,this->m_IsPull
);
133 m_regAutoLoadPutty
= CRegDWORD(regkey
,this->m_bAutoLoad
);
134 m_bAutoLoad
= m_regAutoLoadPutty
;
136 if(!CAppUtils::IsSSHPutty())
141 this->m_bRebase
= m_regRebase
;
145 GetDlgItem(IDC_CHECK_REBASE
)->ShowWindow(SW_HIDE
);
146 this->m_bRebase
= FALSE
;
149 this->UpdateData(FALSE
);
151 this->AddOthersToAnchor();
153 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow(m_bAutoLoadEnable
);
155 CheckRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
,IDC_REMOTE_RD
);
156 m_Remote
.EnableWindow(TRUE
);
157 m_Other
.EnableWindow(FALSE
);
160 m_RemoteBranch
.EnableWindow(FALSE
);
161 GetDlgItem(IDC_BUTTON_BROWSE_REF
)->EnableWindow(FALSE
);
166 GetDlgItem(IDC_CHECK_REBASE
)->ShowWindow(SW_HIDE
);
167 // check tags checkbox and make it a normal checkbox
169 m_bFFonly
= m_regFFonly
;
171 ::SendMessage(GetDlgItem(IDC_CHECK_FETCHTAGS
)->GetSafeHwnd(), BM_SETSTYLE
, GetDlgItem(IDC_CHECK_FETCHTAGS
)->GetStyle() & ~BS_AUTO3STATE
| BS_AUTOCHECKBOX
, 0);
172 OnBnClickedCheckFfonly();
176 this->GetDlgItem(IDC_GROUP_OPTION
)->EnableWindow(FALSE
);
177 this->GetDlgItem(IDC_CHECK_SQUASH
)->EnableWindow(FALSE
);
178 this->GetDlgItem(IDC_CHECK_NOFF
)->EnableWindow(FALSE
);
179 this->GetDlgItem(IDC_CHECK_FFONLY
)->EnableWindow(FALSE
);
180 this->GetDlgItem(IDC_CHECK_NOCOMMIT
)->EnableWindow(FALSE
);
183 if (g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
184 this->GetDlgItem(IDC_CHECK_REBASE
)->EnableWindow(FALSE
);
186 CAutoRepository
repo(g_Git
.GetGitRepository());
188 MessageBox(CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
189 if (repo
&& git_repository_is_shallow(repo
))
196 GetDlgItem(IDC_CHECK_DEPTH
)->ShowWindow(SW_HIDE
);
197 GetDlgItem(IDC_EDIT_DEPTH
)->ShowWindow(SW_HIDE
);
199 OnBnClickedCheckDepth();
201 m_Other
.SetCaseSensitive(TRUE
);
202 m_Other
.SetURLHistory(TRUE
);
203 m_Other
.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
205 m_RemoteBranch
.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
206 m_RemoteBranch
.SetCurSel(0);
208 CString sWindowTitle
;
210 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_PULL
));
212 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH
));
214 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
218 EnableSaveRestore(_T("PullFetchDlg"));
219 this->m_RemoteManage
.SetURL(CString());
223 void CPullFetchDlg::Refresh()
225 //Select pull-remote from current branch
226 CString currentBranch
;
227 if (g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, currentBranch
))
228 currentBranch
.Empty();
230 CString pullRemote
, pullBranch
;
231 g_Git
.GetRemoteTrackedBranch(currentBranch
, pullRemote
, pullBranch
);
232 m_configPullRemote
= pullRemote
;
233 m_configPullBranch
= pullBranch
;
235 if (pullBranch
.IsEmpty())
236 m_RemoteBranch
.AddString(currentBranch
);
238 m_RemoteBranch
.AddString(pullBranch
);
240 if(pullRemote
.IsEmpty())
241 pullRemote
= m_RemoteReg
;
243 if (!m_PreSelectRemote
.IsEmpty())
244 pullRemote
= m_PreSelectRemote
;
249 if(!g_Git
.GetRemoteList(list
))
251 if (!m_IsPull
&& list
.size() > 1)
252 m_Remote
.AddString(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES
)));
254 for (unsigned int i
= 0; i
< list
.size(); ++i
)
256 m_Remote
.AddString(list
[i
]);
257 if (!m_bAllRemotes
&& list
[i
] == pullRemote
)
258 sel
= i
+ (!m_IsPull
&& list
.size() > 1 ? 1 : 0);
261 m_Remote
.SetCurSel(sel
);
262 OnCbnSelchangeRemote();
264 // CPullFetchDlg message handlers
266 void CPullFetchDlg::OnCbnSelchangeRemote()
268 CString remote
= m_Remote
.GetString();
269 if (remote
.IsEmpty() || remote
== CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES
)))
271 GetDlgItem(IDC_STATIC_TAGOPT
)->SetWindowText(_T(""));
272 GetDlgItem(IDC_STATIC_PRUNE
)->SetWindowText(_T(""));
277 key
.Format(_T("remote.%s.tagopt"), remote
);
278 CString tagopt
= g_Git
.GetConfigValue(key
);
279 if (tagopt
== "--no-tags")
280 tagopt
= CString(MAKEINTRESOURCE(IDS_NONE
));
281 else if (tagopt
== "--tags")
282 tagopt
= CString(MAKEINTRESOURCE(CAppUtils::GetMsysgitVersion() < 0x01090000 ? IDS_FETCH_TAGS_ONLY
: IDS_ALL
));
284 tagopt
= CString(MAKEINTRESOURCE(IDS_FETCH_REACHABLE
));
286 value
.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT
)), tagopt
);
287 GetDlgItem(IDC_STATIC_TAGOPT
)->SetWindowText(value
);
290 if (CAppUtils::GetMsysgitVersion() >= 0x01080500)
292 key
.Format(_T("remote.%s.prune"), remote
);
293 prune
= g_Git
.GetConfigValue(key
);
295 prune
= g_Git
.GetConfigValue(_T("fetch.prune"));
297 if (!prune
.IsEmpty())
300 value
.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT
)), prune
);
301 GetDlgItem(IDC_STATIC_PRUNE
)->SetWindowText(value
);
304 GetDlgItem(IDC_STATIC_PRUNE
)->SetWindowText(_T(""));
307 void CPullFetchDlg::OnBnClickedRd()
309 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_REMOTE_RD
)
311 m_Remote
.EnableWindow(TRUE
);
312 m_Other
.EnableWindow(FALSE
);
314 m_RemoteBranch
.EnableWindow(FALSE
);
316 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_OTHER_RD
)
318 CString clippath
= CAppUtils::GetClipboardLink(m_IsPull
? _T("git pull") : _T("git fetch"), 1);
319 if (clippath
.IsEmpty())
320 m_Other
.SetCurSel(0);
323 int argSeparator
= clippath
.Find(' ');
324 if (argSeparator
> 1 && clippath
.GetLength() > argSeparator
+ 2)
326 m_Other
.SetWindowText(clippath
.Left(argSeparator
));
327 m_RemoteBranch
.SetWindowText(clippath
.Mid(argSeparator
+ 1));
330 m_Other
.SetWindowText(clippath
);
332 m_Remote
.EnableWindow(FALSE
);
333 m_Other
.EnableWindow(TRUE
);;
335 m_RemoteBranch
.EnableWindow(TRUE
);
339 void CPullFetchDlg::OnBnClickedOk()
342 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_REMOTE_RD
)
344 m_RemoteURL
=m_Remote
.GetString();
345 m_bAllRemotes
= (m_Remote
.GetCurSel() == 0 && m_Remote
.GetCount() > 1 && !m_IsPull
);
347 (m_configPullRemote
== m_RemoteURL
&& m_configPullBranch
== m_RemoteBranch
.GetString() ))
348 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
349 //because otherwise git will not update the remote tracking branches.
350 m_RemoteBranchName
.Empty();
352 m_RemoteBranchName
=m_RemoteBranch
.GetString();
354 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_OTHER_RD
)
356 m_Other
.GetWindowTextW(m_RemoteURL
);
357 m_RemoteBranchName
=m_RemoteBranch
.GetString();
359 // only store URL in history if it's value was used
360 m_Other
.SaveHistory();
363 m_RemoteReg
= m_Remote
.GetString();
365 m_RemoteBranch
.SaveHistory();
366 this->m_regRebase
=this->m_bRebase
;
367 m_regFFonly
= m_bFFonly
;
369 m_regAutoLoadPutty
= m_bAutoLoad
;
374 void CPullFetchDlg::OnStnClickedRemoteManage()
376 CAppUtils::LaunchRemoteSetting();
380 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
383 initialRef
.Format(L
"refs/remotes/%s/%s", m_Remote
.GetString(), m_RemoteBranch
.GetString());
384 CString selectedRef
= CBrowseRefsDlg::PickRef(false, initialRef
, gPickRef_Remote
);
385 if(selectedRef
.Left(13) != "refs/remotes/")
388 selectedRef
= selectedRef
.Mid(13);
389 int ixSlash
= selectedRef
.Find('/');
391 CString remoteName
= selectedRef
.Left(ixSlash
);
392 CString remoteBranch
= selectedRef
.Mid(ixSlash
+ 1);
394 int ixFound
= m_Remote
.FindStringExact(0, remoteName
);
396 m_Remote
.SetCurSel(ixFound
);
397 m_RemoteBranch
.AddString(remoteBranch
, 0);
399 CheckRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
,IDC_REMOTE_RD
);
402 void CPullFetchDlg::OnBnClickedCheckDepth()
405 GetDlgItem(IDC_EDIT_DEPTH
)->EnableWindow(m_bDepth
);
408 void CPullFetchDlg::OnBnClickedCheckFfonly()
414 GetDlgItem(IDC_CHECK_FFONLY
)->EnableWindow(FALSE
);
418 GetDlgItem(IDC_CHECK_FFONLY
)->EnableWindow(TRUE
);
423 GetDlgItem(IDC_CHECK_NOFF
)->EnableWindow(FALSE
);
427 GetDlgItem(IDC_CHECK_NOFF
)->EnableWindow(TRUE
);