1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012 - 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();;
47 m_bAllRemotes
= FALSE
;
51 CPullFetchDlg::~CPullFetchDlg()
55 void CPullFetchDlg::DoDataExchange(CDataExchange
* pDX
)
57 CDialog::DoDataExchange(pDX
);
58 DDX_Control(pDX
, IDC_REMOTE_COMBO
, this->m_Remote
);
59 DDX_Control(pDX
, IDC_OTHER
, this->m_Other
);
60 DDX_Control(pDX
, IDC_REMOTE_BRANCH
, this->m_RemoteBranch
);
61 DDX_Control(pDX
,IDC_REMOTE_MANAGE
, this->m_RemoteManage
);
62 DDX_Check(pDX
,IDC_CHECK_NOFF
, this->m_bNoFF
);
63 DDX_Check(pDX
,IDC_CHECK_SQUASH
, this->m_bSquash
);
64 DDX_Check(pDX
,IDC_CHECK_NOCOMMIT
, this->m_bNoCommit
);
65 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
,m_bAutoLoad
);
66 DDX_Check(pDX
,IDC_CHECK_REBASE
,m_bRebase
);
67 DDX_Check(pDX
,IDC_CHECK_PRUNE
,m_bPrune
);
68 DDX_Check(pDX
, IDC_CHECK_FFONLY
, m_bFFonly
);
69 DDX_Check(pDX
, IDC_CHECK_FETCHTAGS
, m_bFetchTags
);
73 BEGIN_MESSAGE_MAP(CPullFetchDlg
, CHorizontalResizableStandAloneDialog
)
74 ON_CBN_SELCHANGE(IDC_REMOTE_COMBO
, &CPullFetchDlg::OnCbnSelchangeRemote
)
75 ON_BN_CLICKED(IDC_REMOTE_RD
, &CPullFetchDlg::OnBnClickedRd
)
76 ON_BN_CLICKED(IDC_OTHER_RD
, &CPullFetchDlg::OnBnClickedRd
)
77 ON_BN_CLICKED(IDOK
, &CPullFetchDlg::OnBnClickedOk
)
78 ON_STN_CLICKED(IDC_REMOTE_MANAGE
, &CPullFetchDlg::OnStnClickedRemoteManage
)
79 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF
, &CPullFetchDlg::OnBnClickedButtonBrowseRef
)
82 BOOL
CPullFetchDlg::OnInitDialog()
84 CHorizontalResizableStandAloneDialog::OnInitDialog();
85 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
87 AddAnchor(IDC_REMOTE_COMBO
, TOP_LEFT
, TOP_RIGHT
);
88 AddAnchor(IDC_OTHER
, TOP_LEFT
,TOP_RIGHT
);
90 AddAnchor(IDC_REMOTE_BRANCH
, TOP_LEFT
,TOP_RIGHT
);
91 AddAnchor(IDC_BUTTON_BROWSE_REF
,TOP_RIGHT
);
93 AddAnchor(IDOK
,BOTTOM_RIGHT
);
94 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
95 AddAnchor(IDC_GROUPT_REMOTE
,TOP_LEFT
,TOP_RIGHT
);
96 AddAnchor(IDC_GROUP_OPTION
,TOP_LEFT
,TOP_RIGHT
);
97 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,BOTTOM_LEFT
);
98 AddAnchor(IDC_CHECK_PRUNE
,BOTTOM_LEFT
);
99 AddAnchor(IDC_CHECK_REBASE
,BOTTOM_LEFT
);
100 AddAnchor(IDC_REMOTE_MANAGE
,BOTTOM_LEFT
);
101 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
103 AdjustControlSize(IDC_REMOTE_RD
);
104 AdjustControlSize(IDC_OTHER_RD
);
105 AdjustControlSize(IDC_CHECK_SQUASH
);
106 AdjustControlSize(IDC_CHECK_NOCOMMIT
);
107 AdjustControlSize(IDC_CHECK_NOFF
);
108 AdjustControlSize(IDC_CHECK_FFONLY
);
109 AdjustControlSize(IDC_CHECK_FETCHTAGS
);
110 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD
);
111 AdjustControlSize(IDC_CHECK_REBASE
);
112 AdjustControlSize(IDC_CHECK_PRUNE
);
114 CString WorkingDir
=g_Git
.m_CurrentDir
;
115 WorkingDir
.Replace(_T(':'),_T('_'));
117 m_RemoteReg
= CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir
));
119 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir
,this->m_IsPull
);
120 m_regRebase
=CRegDWORD(regkey
,false);
121 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir
,this->m_IsPull
);
123 m_regAutoLoadPutty
= CRegDWORD(regkey
,this->m_bAutoLoad
);
124 m_bAutoLoad
= m_regAutoLoadPutty
;
126 if(!CAppUtils::IsSSHPutty())
131 this->m_bRebase
= m_regRebase
;
135 GetDlgItem(IDC_CHECK_REBASE
)->ShowWindow(SW_HIDE
);
136 this->m_bRebase
= FALSE
;
139 this->UpdateData(FALSE
);
141 this->AddOthersToAnchor();
143 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow(m_bAutoLoadEnable
);
145 CheckRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
,IDC_REMOTE_RD
);
146 m_Remote
.EnableWindow(TRUE
);
147 m_Other
.EnableWindow(FALSE
);
150 m_RemoteBranch
.EnableWindow(FALSE
);
151 GetDlgItem(IDC_BUTTON_BROWSE_REF
)->EnableWindow(FALSE
);
156 GetDlgItem(IDC_CHECK_REBASE
)->ShowWindow(SW_HIDE
);
157 GetDlgItem(IDC_CHECK_PRUNE
)->ShowWindow(SW_HIDE
);
158 // check tags checkbox and make it a normal checkbox
161 ::SendMessage(GetDlgItem(IDC_CHECK_FETCHTAGS
)->GetSafeHwnd(), BM_SETSTYLE
, GetDlgItem(IDC_CHECK_FETCHTAGS
)->GetStyle() & ~BS_AUTO3STATE
| BS_AUTOCHECKBOX
, 0);
165 this->GetDlgItem(IDC_GROUP_OPTION
)->EnableWindow(FALSE
);
166 this->GetDlgItem(IDC_CHECK_SQUASH
)->EnableWindow(FALSE
);
167 this->GetDlgItem(IDC_CHECK_NOFF
)->EnableWindow(FALSE
);
168 this->GetDlgItem(IDC_CHECK_FFONLY
)->EnableWindow(FALSE
);
169 this->GetDlgItem(IDC_CHECK_NOCOMMIT
)->EnableWindow(FALSE
);
172 if (g_GitAdminDir
.IsBareRepo(g_Git
.m_CurrentDir
))
173 this->GetDlgItem(IDC_CHECK_REBASE
)->EnableWindow(FALSE
);
175 m_Other
.SetURLHistory(TRUE
);
176 m_Other
.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
177 CString clippath
=CAppUtils::GetClipboardLink();
178 if(clippath
.IsEmpty())
179 m_Other
.SetCurSel(0);
181 m_Other
.SetWindowText(clippath
);
183 m_RemoteBranch
.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
184 m_RemoteBranch
.SetCurSel(0);
186 CString sWindowTitle
;
188 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_PULL
));
190 sWindowTitle
= CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_FETCH
));
192 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
196 EnableSaveRestore(_T("PullFetchDlg"));
197 this->m_RemoteManage
.SetURL(CString());
201 void CPullFetchDlg::Refresh()
203 //Select pull-remote from current branch
204 CString currentBranch
= g_Git
.GetSymbolicRef();
206 configName
.Format(L
"branch.%s.remote", currentBranch
);
207 CString pullRemote
= this->m_configPullRemote
= g_Git
.GetConfigValue(configName
);
209 //Select pull-branch from current branch
210 configName
.Format(L
"branch.%s.merge", currentBranch
);
211 CString pullBranch
= m_configPullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
212 if (pullBranch
.IsEmpty())
213 m_RemoteBranch
.AddString(currentBranch
);
215 m_RemoteBranch
.AddString(pullBranch
);
217 if(pullRemote
.IsEmpty())
218 pullRemote
= m_RemoteReg
;
220 if (!m_PreSelectRemote
.IsEmpty())
221 pullRemote
= m_PreSelectRemote
;
226 list
.push_back(_T("- all -"));
227 if(!g_Git
.GetRemoteList(list
))
229 if (!m_IsPull
&& list
.size() <= 2)
230 list
.erase(list
.begin());
232 for(unsigned int i
=0;i
<list
.size();i
++)
234 m_Remote
.AddString(list
[i
]);
235 if(list
[i
] == pullRemote
)
239 m_Remote
.SetCurSel(sel
);
240 OnCbnSelchangeRemote();
242 // CPullFetchDlg message handlers
244 void CPullFetchDlg::OnCbnSelchangeRemote()
246 CString remote
= m_Remote
.GetString();
247 if (remote
.IsEmpty() || remote
== _T("- all -"))
249 GetDlgItem(IDC_STATIC_TAGOPT
)->SetWindowText(_T(""));
254 key
.Format(_T("remote.%s.tagopt"), remote
);
255 CString tagopt
= g_Git
.GetConfigValue(key
);
256 if (tagopt
== "--no-tags")
257 tagopt
= CString(MAKEINTRESOURCE(IDS_NONE
));
258 else if (tagopt
== "--tags")
259 tagopt
= CString(MAKEINTRESOURCE(IDS_FETCH_TAGS_ONLY
));
261 tagopt
= CString(MAKEINTRESOURCE(IDS_FETCH_REACHABLE
));
263 value
.Format(_T("%s: %s"), CString(MAKEINTRESOURCE(IDS_DEFAULT
)), tagopt
);
264 GetDlgItem(IDC_STATIC_TAGOPT
)->SetWindowText(value
);
267 void CPullFetchDlg::OnBnClickedRd()
269 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_REMOTE_RD
)
271 m_Remote
.EnableWindow(TRUE
);
272 m_Other
.EnableWindow(FALSE
);
274 m_RemoteBranch
.EnableWindow(FALSE
);
276 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_OTHER_RD
)
278 m_Remote
.EnableWindow(FALSE
);
279 m_Other
.EnableWindow(TRUE
);;
281 m_RemoteBranch
.EnableWindow(TRUE
);
285 void CPullFetchDlg::OnBnClickedOk()
288 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_REMOTE_RD
)
290 m_RemoteURL
=m_Remote
.GetString();
291 m_bAllRemotes
= (m_Remote
.GetCurSel() == 0 && m_Remote
.GetCount() > 1 && !m_IsPull
);
293 (m_configPullRemote
== m_RemoteURL
&& m_configPullBranch
== m_RemoteBranch
.GetString() ))
294 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
295 //because otherwise git will not update the remote tracking branches.
296 m_RemoteBranchName
.Empty();
298 m_RemoteBranchName
=m_RemoteBranch
.GetString();
300 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_OTHER_RD
)
302 m_Other
.GetWindowTextW(m_RemoteURL
);
303 m_RemoteBranchName
=m_RemoteBranch
.GetString();
306 m_RemoteReg
= m_Remote
.GetString();
308 m_Other
.SaveHistory();
309 m_RemoteBranch
.SaveHistory();
310 this->m_regRebase
=this->m_bRebase
;
312 m_regAutoLoadPutty
= m_bAutoLoad
;
317 void CPullFetchDlg::OnStnClickedRemoteManage()
319 CAppUtils::LaunchRemoteSetting();
323 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
326 initialRef
.Format(L
"refs/remotes/%s/%s", m_Remote
.GetString(), m_RemoteBranch
.GetString());
327 CString selectedRef
= CBrowseRefsDlg::PickRef(false, initialRef
, gPickRef_Remote
);
328 if(selectedRef
.Left(13) != "refs/remotes/")
331 selectedRef
= selectedRef
.Mid(13);
332 int ixSlash
= selectedRef
.Find('/');
334 CString remoteName
= selectedRef
.Left(ixSlash
);
335 CString remoteBranch
= selectedRef
.Mid(ixSlash
+ 1);
337 int ixFound
= m_Remote
.FindStringExact(0, remoteName
);
339 m_Remote
.SetCurSel(ixFound
);
340 m_RemoteBranch
.AddString(remoteBranch
, 0);
342 CheckRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
,IDC_REMOTE_RD
);