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 OnBnClickedCheckDepth();
188 m_Other
.SetCaseSensitive(TRUE
);
189 m_Other
.SetURLHistory(TRUE
);
190 m_Other
.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
192 m_RemoteBranch
.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
193 m_RemoteBranch
.SetCurSel(0);
195 CString sWindowTitle
;
197 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_PULL
));
199 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH
));
201 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
205 EnableSaveRestore(_T("PullFetchDlg"));
206 this->m_RemoteManage
.SetURL(CString());
210 void CPullFetchDlg::Refresh()
212 //Select pull-remote from current branch
213 CString currentBranch
;
214 if (g_Git
.GetCurrentBranchFromFile(g_Git
.m_CurrentDir
, currentBranch
))
215 currentBranch
.Empty();
217 CString pullRemote
, pullBranch
;
218 g_Git
.GetRemoteTrackedBranch(currentBranch
, pullRemote
, pullBranch
);
219 m_configPullRemote
= pullRemote
;
220 m_configPullBranch
= pullBranch
;
222 if (pullBranch
.IsEmpty())
223 m_RemoteBranch
.AddString(currentBranch
);
225 m_RemoteBranch
.AddString(pullBranch
);
227 if(pullRemote
.IsEmpty())
228 pullRemote
= m_RemoteReg
;
230 if (!m_PreSelectRemote
.IsEmpty())
231 pullRemote
= m_PreSelectRemote
;
236 if(!g_Git
.GetRemoteList(list
))
238 if (!m_IsPull
&& list
.size() > 1)
239 m_Remote
.AddString(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES
)));
241 for (unsigned int i
= 0; i
< list
.size(); ++i
)
243 m_Remote
.AddString(list
[i
]);
244 if (!m_bAllRemotes
&& list
[i
] == pullRemote
)
245 sel
= i
+ (!m_IsPull
&& list
.size() > 1 ? 1 : 0);
248 m_Remote
.SetCurSel(sel
);
249 OnCbnSelchangeRemote();
251 // CPullFetchDlg message handlers
253 void CPullFetchDlg::OnCbnSelchangeRemote()
255 CString remote
= m_Remote
.GetString();
256 if (remote
.IsEmpty() || remote
== CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES
)))
258 GetDlgItem(IDC_STATIC_TAGOPT
)->SetWindowText(_T(""));
259 GetDlgItem(IDC_STATIC_PRUNE
)->SetWindowText(_T(""));
264 key
.Format(_T("remote.%s.tagopt"), remote
);
265 CString tagopt
= g_Git
.GetConfigValue(key
);
266 if (tagopt
== "--no-tags")
267 tagopt
= CString(MAKEINTRESOURCE(IDS_NONE
));
268 else if (tagopt
== "--tags")
269 tagopt
= CString(MAKEINTRESOURCE(CAppUtils::GetMsysgitVersion() < 0x01090000 ? IDS_FETCH_TAGS_ONLY
: IDS_ALL
));
271 tagopt
= CString(MAKEINTRESOURCE(IDS_FETCH_REACHABLE
));
273 value
.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT
)), tagopt
);
274 GetDlgItem(IDC_STATIC_TAGOPT
)->SetWindowText(value
);
277 if (CAppUtils::GetMsysgitVersion() >= 0x01080500)
279 key
.Format(_T("remote.%s.prune"), remote
);
280 prune
= g_Git
.GetConfigValue(key
);
282 prune
= g_Git
.GetConfigValue(_T("fetch.prune"));
284 if (!prune
.IsEmpty())
287 value
.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT
)), prune
);
288 GetDlgItem(IDC_STATIC_PRUNE
)->SetWindowText(value
);
291 GetDlgItem(IDC_STATIC_PRUNE
)->SetWindowText(_T(""));
294 void CPullFetchDlg::OnBnClickedRd()
296 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_REMOTE_RD
)
298 m_Remote
.EnableWindow(TRUE
);
299 m_Other
.EnableWindow(FALSE
);
301 m_RemoteBranch
.EnableWindow(FALSE
);
303 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_OTHER_RD
)
305 CString clippath
= CAppUtils::GetClipboardLink(m_IsPull
? _T("git pull") : _T("git fetch"), 1);
306 if (clippath
.IsEmpty())
307 m_Other
.SetCurSel(0);
310 int argSeparator
= clippath
.Find(' ');
311 if (argSeparator
> 1 && clippath
.GetLength() > argSeparator
+ 2)
313 m_Other
.SetWindowText(clippath
.Left(argSeparator
));
314 m_RemoteBranch
.SetWindowText(clippath
.Mid(argSeparator
+ 1));
317 m_Other
.SetWindowText(clippath
);
319 m_Remote
.EnableWindow(FALSE
);
320 m_Other
.EnableWindow(TRUE
);;
322 m_RemoteBranch
.EnableWindow(TRUE
);
326 void CPullFetchDlg::OnBnClickedOk()
329 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_REMOTE_RD
)
331 m_RemoteURL
=m_Remote
.GetString();
332 m_bAllRemotes
= (m_Remote
.GetCurSel() == 0 && m_Remote
.GetCount() > 1 && !m_IsPull
);
334 (m_configPullRemote
== m_RemoteURL
&& m_configPullBranch
== m_RemoteBranch
.GetString() ))
335 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
336 //because otherwise git will not update the remote tracking branches.
337 m_RemoteBranchName
.Empty();
339 m_RemoteBranchName
=m_RemoteBranch
.GetString();
341 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_OTHER_RD
)
343 m_Other
.GetWindowTextW(m_RemoteURL
);
344 m_RemoteBranchName
=m_RemoteBranch
.GetString();
346 // only store URL in history if it's value was used
347 m_Other
.SaveHistory();
350 m_RemoteReg
= m_Remote
.GetString();
352 m_RemoteBranch
.SaveHistory();
353 this->m_regRebase
=this->m_bRebase
;
354 m_regFFonly
= m_bFFonly
;
356 m_regAutoLoadPutty
= m_bAutoLoad
;
361 void CPullFetchDlg::OnStnClickedRemoteManage()
363 CAppUtils::LaunchRemoteSetting();
367 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
370 initialRef
.Format(L
"refs/remotes/%s/%s", m_Remote
.GetString(), m_RemoteBranch
.GetString());
371 CString selectedRef
= CBrowseRefsDlg::PickRef(false, initialRef
, gPickRef_Remote
);
372 if(selectedRef
.Left(13) != "refs/remotes/")
375 selectedRef
= selectedRef
.Mid(13);
376 int ixSlash
= selectedRef
.Find('/');
378 CString remoteName
= selectedRef
.Left(ixSlash
);
379 CString remoteBranch
= selectedRef
.Mid(ixSlash
+ 1);
381 int ixFound
= m_Remote
.FindStringExact(0, remoteName
);
383 m_Remote
.SetCurSel(ixFound
);
384 m_RemoteBranch
.AddString(remoteBranch
, 0);
386 CheckRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
,IDC_REMOTE_RD
);
389 void CPullFetchDlg::OnBnClickedCheckDepth()
392 GetDlgItem(IDC_EDIT_DEPTH
)->EnableWindow(m_bDepth
);
395 void CPullFetchDlg::OnBnClickedCheckFfonly()
401 GetDlgItem(IDC_CHECK_FFONLY
)->EnableWindow(FALSE
);
405 GetDlgItem(IDC_CHECK_FFONLY
)->EnableWindow(TRUE
);
410 GetDlgItem(IDC_CHECK_NOFF
)->EnableWindow(FALSE
);
414 GetDlgItem(IDC_CHECK_NOFF
)->EnableWindow(TRUE
);