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_bAutoLoad
= CAppUtils::IsSSHPutty();
38 m_bAutoLoadEnable
=CAppUtils::IsSSHPutty();;
48 m_bAllRemotes
= FALSE
;
49 m_bPrune
= CAppUtils::GetMsysgitVersion() >= 0x01080500 ? 2 : FALSE
;
52 CPullFetchDlg::~CPullFetchDlg()
56 void CPullFetchDlg::DoDataExchange(CDataExchange
* pDX
)
58 CDialog::DoDataExchange(pDX
);
59 DDX_Control(pDX
, IDC_REMOTE_COMBO
, this->m_Remote
);
60 DDX_Control(pDX
, IDC_OTHER
, this->m_Other
);
61 DDX_Control(pDX
, IDC_REMOTE_BRANCH
, this->m_RemoteBranch
);
62 DDX_Control(pDX
,IDC_REMOTE_MANAGE
, this->m_RemoteManage
);
63 DDX_Check(pDX
,IDC_CHECK_NOFF
, this->m_bNoFF
);
64 DDX_Check(pDX
,IDC_CHECK_SQUASH
, this->m_bSquash
);
65 DDX_Check(pDX
,IDC_CHECK_NOCOMMIT
, this->m_bNoCommit
);
66 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
,m_bAutoLoad
);
67 DDX_Check(pDX
,IDC_CHECK_REBASE
,m_bRebase
);
68 DDX_Check(pDX
,IDC_CHECK_PRUNE
,m_bPrune
);
69 DDX_Check(pDX
, IDC_CHECK_DEPTH
, m_bDepth
);
70 DDX_Text(pDX
, IDC_EDIT_DEPTH
, m_nDepth
);
71 DDX_Check(pDX
, IDC_CHECK_FFONLY
, m_bFFonly
);
72 DDX_Check(pDX
, IDC_CHECK_FETCHTAGS
, m_bFetchTags
);
76 BEGIN_MESSAGE_MAP(CPullFetchDlg
, CHorizontalResizableStandAloneDialog
)
77 ON_CBN_SELCHANGE(IDC_REMOTE_COMBO
, &CPullFetchDlg::OnCbnSelchangeRemote
)
78 ON_BN_CLICKED(IDC_REMOTE_RD
, &CPullFetchDlg::OnBnClickedRd
)
79 ON_BN_CLICKED(IDC_OTHER_RD
, &CPullFetchDlg::OnBnClickedRd
)
80 ON_BN_CLICKED(IDOK
, &CPullFetchDlg::OnBnClickedOk
)
81 ON_STN_CLICKED(IDC_REMOTE_MANAGE
, &CPullFetchDlg::OnStnClickedRemoteManage
)
82 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF
, &CPullFetchDlg::OnBnClickedButtonBrowseRef
)
83 ON_BN_CLICKED(IDC_CHECK_DEPTH
, OnBnClickedCheckDepth
)
84 ON_BN_CLICKED(IDC_CHECK_FETCHTAGS
, OnBnClickedCheckFetchtags
)
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())
139 m_bRebase
= m_regRebase
;
141 CAutoRepository
repo(g_Git
.GetGitRepository());
143 MessageBox(CGit::GetLibGit2LastErr(_T("Could not open repository.")), _T("TortoiseGit"), MB_OK
| MB_ICONERROR
);
145 // Check config branch.<name>.rebase and pull.reabse
153 if (git_repository_head_detached(repo
) == 1)
156 CAutoConfig
config(true);
157 if (git_repository_config(config
.GetPointer(), repo
))
161 // branch.<name>.rebase overrides pull.rebase
162 if (config
.GetBOOL(_T("branch.") + g_Git
.GetCurrentBranch() + _T(".rebase"), rebase
) == GIT_ENOTFOUND
)
164 if (config
.GetBOOL(_T("pull.rebase"), rebase
) == GIT_ENOTFOUND
)
170 // Since rebase = true in config, means that "git.exe pull" will ALWAYS rebase without "--rebase".
171 // So, lock it, then let Fetch Rebase do the rest things.
172 GetDlgItem(IDC_CHECK_REBASE
)->EnableWindow(FALSE
);
176 this->UpdateData(FALSE
);
178 this->AddOthersToAnchor();
180 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow(m_bAutoLoadEnable
);
182 CheckRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
,IDC_REMOTE_RD
);
183 m_Remote
.EnableWindow(TRUE
);
184 m_Other
.EnableWindow(FALSE
);
187 m_RemoteBranch
.EnableWindow(FALSE
);
188 GetDlgItem(IDC_BUTTON_BROWSE_REF
)->EnableWindow(FALSE
);
193 m_bFFonly
= m_regFFonly
;
195 OnBnClickedCheckFfonly();
199 this->GetDlgItem(IDC_GROUP_OPTION
)->EnableWindow(FALSE
);
200 this->GetDlgItem(IDC_CHECK_SQUASH
)->EnableWindow(FALSE
);
201 this->GetDlgItem(IDC_CHECK_NOFF
)->EnableWindow(FALSE
);
202 this->GetDlgItem(IDC_CHECK_FFONLY
)->EnableWindow(FALSE
);
203 this->GetDlgItem(IDC_CHECK_NOCOMMIT
)->EnableWindow(FALSE
);
206 if (g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
207 this->GetDlgItem(IDC_CHECK_REBASE
)->EnableWindow(FALSE
);
209 if (repo
&& git_repository_is_shallow(repo
))
216 GetDlgItem(IDC_CHECK_DEPTH
)->ShowWindow(SW_HIDE
);
217 GetDlgItem(IDC_EDIT_DEPTH
)->ShowWindow(SW_HIDE
);
219 OnBnClickedCheckDepth();
221 m_Other
.SetCaseSensitive(TRUE
);
222 m_Other
.SetURLHistory(TRUE
);
223 m_Other
.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
225 m_RemoteBranch
.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
226 m_RemoteBranch
.SetCurSel(0);
228 CString sWindowTitle
;
230 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_PULL
));
232 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH
));
234 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
238 EnableSaveRestore(_T("PullFetchDlg"));
239 this->m_RemoteManage
.SetURL(CString());
243 void CPullFetchDlg::Refresh()
245 //Select pull-remote from current branch
246 CString currentBranch
;
247 if (g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, currentBranch
))
248 currentBranch
.Empty();
250 CString pullRemote
, pullBranch
;
251 g_Git
.GetRemoteTrackedBranch(currentBranch
, pullRemote
, pullBranch
);
252 m_configPullRemote
= pullRemote
;
253 m_configPullBranch
= pullBranch
;
255 if (pullBranch
.IsEmpty())
256 m_RemoteBranch
.AddString(currentBranch
);
258 m_RemoteBranch
.AddString(pullBranch
);
260 if(pullRemote
.IsEmpty())
261 pullRemote
= m_RemoteReg
;
263 if (!m_PreSelectRemote
.IsEmpty())
264 pullRemote
= m_PreSelectRemote
;
269 if(!g_Git
.GetRemoteList(list
))
271 if (!m_IsPull
&& list
.size() > 1)
272 m_Remote
.AddString(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES
)));
274 for (unsigned int i
= 0; i
< list
.size(); ++i
)
276 m_Remote
.AddString(list
[i
]);
277 if (!m_bAllRemotes
&& list
[i
] == pullRemote
)
278 sel
= i
+ (!m_IsPull
&& list
.size() > 1 ? 1 : 0);
281 m_Remote
.SetCurSel(sel
);
282 OnCbnSelchangeRemote();
284 // CPullFetchDlg message handlers
286 void CPullFetchDlg::OnCbnSelchangeRemote()
288 CString remote
= m_Remote
.GetString();
289 if (remote
.IsEmpty() || remote
== CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES
)))
291 GetDlgItem(IDC_STATIC_TAGOPT
)->SetWindowText(_T(""));
292 GetDlgItem(IDC_STATIC_PRUNE
)->SetWindowText(_T(""));
297 key
.Format(_T("remote.%s.tagopt"), remote
);
298 CString tagopt
= g_Git
.GetConfigValue(key
);
299 if (tagopt
== "--no-tags")
300 tagopt
= CString(MAKEINTRESOURCE(IDS_NONE
));
301 else if (tagopt
== "--tags")
302 tagopt
= CString(MAKEINTRESOURCE(CAppUtils::GetMsysgitVersion() < 0x01090000 ? IDS_FETCH_TAGS_ONLY
: IDS_ALL
));
304 tagopt
= CString(MAKEINTRESOURCE(IDS_FETCH_REACHABLE
));
306 value
.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT
)), tagopt
);
307 GetDlgItem(IDC_STATIC_TAGOPT
)->SetWindowText(value
);
310 if (CAppUtils::GetMsysgitVersion() >= 0x01080500)
312 key
.Format(_T("remote.%s.prune"), remote
);
313 prune
= g_Git
.GetConfigValue(key
);
315 prune
= g_Git
.GetConfigValue(_T("fetch.prune"));
317 if (!prune
.IsEmpty())
320 value
.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT
)), prune
);
321 GetDlgItem(IDC_STATIC_PRUNE
)->SetWindowText(value
);
324 GetDlgItem(IDC_STATIC_PRUNE
)->SetWindowText(_T(""));
327 void CPullFetchDlg::OnBnClickedRd()
329 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_REMOTE_RD
)
331 m_Remote
.EnableWindow(TRUE
);
332 m_Other
.EnableWindow(FALSE
);
334 m_RemoteBranch
.EnableWindow(FALSE
);
336 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_OTHER_RD
)
338 CString clippath
= CAppUtils::GetClipboardLink(m_IsPull
? _T("git pull") : _T("git fetch"), 1);
339 if (clippath
.IsEmpty())
340 m_Other
.SetCurSel(0);
343 int argSeparator
= clippath
.Find(' ');
344 if (argSeparator
> 1 && clippath
.GetLength() > argSeparator
+ 2)
346 m_Other
.SetWindowText(clippath
.Left(argSeparator
));
347 m_RemoteBranch
.SetWindowText(clippath
.Mid(argSeparator
+ 1));
350 m_Other
.SetWindowText(clippath
);
352 m_Remote
.EnableWindow(FALSE
);
353 m_Other
.EnableWindow(TRUE
);;
355 m_RemoteBranch
.EnableWindow(TRUE
);
359 void CPullFetchDlg::OnBnClickedOk()
362 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_REMOTE_RD
)
364 m_RemoteURL
=m_Remote
.GetString();
365 m_bAllRemotes
= (m_Remote
.GetCurSel() == 0 && m_Remote
.GetCount() > 1 && !m_IsPull
);
367 (m_configPullRemote
== m_RemoteURL
&& m_configPullBranch
== m_RemoteBranch
.GetString() ))
368 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
369 //because otherwise git will not update the remote tracking branches.
370 m_RemoteBranchName
.Empty();
372 m_RemoteBranchName
=m_RemoteBranch
.GetString();
374 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_OTHER_RD
)
376 m_Other
.GetWindowTextW(m_RemoteURL
);
377 m_RemoteBranchName
=m_RemoteBranch
.GetString();
379 // only store URL in history if it's value was used
380 m_Other
.SaveHistory();
383 m_RemoteReg
= m_Remote
.GetString();
385 m_RemoteBranch
.SaveHistory();
386 this->m_regRebase
=this->m_bRebase
;
387 m_regFFonly
= m_bFFonly
;
389 m_regAutoLoadPutty
= m_bAutoLoad
;
394 void CPullFetchDlg::OnStnClickedRemoteManage()
396 CAppUtils::LaunchRemoteSetting();
400 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
403 initialRef
.Format(L
"refs/remotes/%s/%s", m_Remote
.GetString(), m_RemoteBranch
.GetString());
404 CString selectedRef
= CBrowseRefsDlg::PickRef(false, initialRef
, gPickRef_Remote
);
405 if(selectedRef
.Left(13) != "refs/remotes/")
408 selectedRef
= selectedRef
.Mid(13);
409 int ixSlash
= selectedRef
.Find('/');
411 CString remoteName
= selectedRef
.Left(ixSlash
);
412 CString remoteBranch
= selectedRef
.Mid(ixSlash
+ 1);
414 int ixFound
= m_Remote
.FindStringExact(0, remoteName
);
416 m_Remote
.SetCurSel(ixFound
);
417 m_RemoteBranch
.AddString(remoteBranch
, 0);
419 CheckRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
,IDC_REMOTE_RD
);
422 void CPullFetchDlg::OnBnClickedCheckDepth()
425 GetDlgItem(IDC_EDIT_DEPTH
)->EnableWindow(m_bDepth
);
428 void CPullFetchDlg::OnBnClickedCheckFetchtags()
430 if (CAppUtils::GetMsysgitVersion() < 0x01090000)
433 if (m_bFetchTags
== TRUE
)
439 void CPullFetchDlg::OnBnClickedCheckFfonly()
445 GetDlgItem(IDC_CHECK_FFONLY
)->EnableWindow(FALSE
);
449 GetDlgItem(IDC_CHECK_FFONLY
)->EnableWindow(TRUE
);
454 GetDlgItem(IDC_CHECK_NOFF
)->EnableWindow(FALSE
);
458 GetDlgItem(IDC_CHECK_NOFF
)->EnableWindow(TRUE
);