Fixed issue #2167: Support git push --force-with-lease option
[TortoiseGit.git] / src / TortoiseProc / PushDlg.cpp
blob15f98198599adc66cf244b47d196e40c77af3a4f
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 // PushDlg.cpp : implementation file
23 #include "stdafx.h"
24 #include "TortoiseProc.h"
25 #include "PushDlg.h"
27 #include "Git.h"
28 #include "registry.h"
29 #include "AppUtils.h"
30 #include "LogDlg.h"
31 #include "BrowseRefsDlg.h"
32 #include "RefLogDlg.h"
33 #include "MessageBox.h"
35 // CPushDlg dialog
37 IMPLEMENT_DYNAMIC(CPushDlg, CHorizontalResizableStandAloneDialog)
39 CPushDlg::CPushDlg(CWnd* pParent /*=NULL*/)
40 : CHorizontalResizableStandAloneDialog(CPushDlg::IDD, pParent)
41 , m_bPushAllBranches(FALSE)
42 , m_bForce(FALSE)
43 , m_bForceWithLease(FALSE)
44 , m_bPack(FALSE)
45 , m_bTags(FALSE)
46 , m_bAutoLoad(FALSE)
47 , m_bPushAllRemotes(FALSE)
48 , m_bSetPushBranch(FALSE)
49 , m_bSetPushRemote(FALSE)
50 , m_bSetUpstream(FALSE)
51 , m_RecurseSubmodules(0)
53 m_bAutoLoad = CAppUtils::IsSSHPutty();
56 CPushDlg::~CPushDlg()
60 void CPushDlg::DoDataExchange(CDataExchange* pDX)
62 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
63 DDX_Control(pDX, IDC_BRANCH_REMOTE, this->m_BranchRemote);
64 DDX_Control(pDX, IDC_BRANCH_SOURCE, this->m_BranchSource);
65 DDX_Control(pDX, IDC_REMOTE, this->m_Remote);
66 DDX_Control(pDX, IDC_URL, this->m_RemoteURL);
67 DDX_Control(pDX, IDC_BUTTON_BROWSE_SOURCE_BRANCH, m_BrowseLocalRef);
68 DDX_Control(pDX, IDC_COMBOBOX_RECURSE_SUBMODULES, m_RecurseSubmodulesCombo);
69 DDX_Check(pDX,IDC_FORCE,this->m_bForce);
70 DDX_Check(pDX, IDC_FORCE_WITH_LEASE, m_bForceWithLease);
71 DDX_Check(pDX,IDC_PUSHALL,this->m_bPushAllBranches);
72 DDX_Check(pDX,IDC_PACK,this->m_bPack);
73 DDX_Check(pDX,IDC_TAGS,this->m_bTags);
74 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,this->m_bAutoLoad);
75 DDX_Check(pDX, IDC_PROC_PUSH_SET_PUSHREMOTE, m_bSetPushRemote);
76 DDX_Check(pDX, IDC_PROC_PUSH_SET_PUSHBRANCH, m_bSetPushBranch);
77 DDX_Check(pDX, IDC_PROC_PUSH_SET_UPSTREAM, m_bSetUpstream);
80 BEGIN_MESSAGE_MAP(CPushDlg, CHorizontalResizableStandAloneDialog)
81 ON_BN_CLICKED(IDC_RD_REMOTE, &CPushDlg::OnBnClickedRd)
82 ON_BN_CLICKED(IDC_RD_URL, &CPushDlg::OnBnClickedRd)
83 ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE, &CPushDlg::OnCbnSelchangeBranchSource)
84 ON_CBN_SELCHANGE(IDC_REMOTE, &CPushDlg::EnDisablePushRemoteArchiveBranch)
85 ON_BN_CLICKED(IDOK, &CPushDlg::OnBnClickedOk)
86 ON_BN_CLICKED(IDC_REMOTE_MANAGE, &CPushDlg::OnBnClickedRemoteManage)
87 ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH, &CPushDlg::OnBnClickedButtonBrowseSourceBranch)
88 ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH, &CPushDlg::OnBnClickedButtonBrowseDestBranch)
89 ON_BN_CLICKED(IDC_PUSHALL, &CPushDlg::OnBnClickedPushall)
90 ON_BN_CLICKED(IDC_FORCE, &CPushDlg::OnBnClickedForce)
91 ON_BN_CLICKED(IDC_FORCE_WITH_LEASE, &CPushDlg::OnBnClickedForceWithLease)
92 ON_BN_CLICKED(IDC_PROC_PUSH_SET_UPSTREAM, &CPushDlg::OnBnClickedProcPushSetUpstream)
93 ON_BN_CLICKED(IDC_PROC_PUSH_SET_PUSHREMOTE, &CPushDlg::OnBnClickedProcPushSetPushremote)
94 ON_BN_CLICKED(IDC_PROC_PUSH_SET_PUSHBRANCH, &CPushDlg::OnBnClickedProcPushSetPushremote)
95 END_MESSAGE_MAP()
97 BOOL CPushDlg::OnInitDialog()
99 CHorizontalResizableStandAloneDialog::OnInitDialog();
100 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
102 AddAnchor(IDOK,BOTTOM_RIGHT);
103 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
104 AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);
105 AddAnchor(IDC_STATIC_REMOTE, TOP_LEFT);
106 AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);
108 AddAnchor(IDC_PUSHALL, TOP_LEFT);
109 AddAnchor(IDC_BRANCH_REMOTE, TOP_LEFT, TOP_RIGHT);
110 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);
111 AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT, TOP_RIGHT);
112 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_RIGHT);
114 AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);
115 AddAnchor(IDC_RD_REMOTE, TOP_LEFT);
116 AddAnchor(IDC_RD_URL, TOP_LEFT);
118 AddAnchor(IDC_REMOTE, TOP_LEFT, TOP_RIGHT);
120 AddAnchor(IDC_URL, TOP_LEFT,TOP_RIGHT);
122 AddAnchor(IDC_OPTION_GROUP, TOP_LEFT,TOP_RIGHT);
124 AddAnchor(IDC_FORCE, TOP_LEFT);
125 AddAnchor(IDC_FORCE_WITH_LEASE, TOP_LEFT);
126 AddAnchor(IDC_PACK, TOP_LEFT);
127 AddAnchor(IDC_TAGS, TOP_LEFT);
128 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);
129 AddAnchor(IDC_PROC_PUSH_SET_PUSHBRANCH, TOP_LEFT);
130 AddAnchor(IDC_PROC_PUSH_SET_PUSHREMOTE, TOP_LEFT);
131 AddAnchor(IDC_PROC_PUSH_SET_UPSTREAM, TOP_LEFT);
132 AddAnchor(IDC_STATIC_RECURSE_SUBMODULES, TOP_LEFT);
133 AddAnchor(IDC_COMBOBOX_RECURSE_SUBMODULES, TOP_LEFT);
135 AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);
136 AddAnchor(IDHELP, BOTTOM_RIGHT);
138 AddOthersToAnchor();
140 AdjustControlSize(IDC_RD_REMOTE);
141 AdjustControlSize(IDC_RD_URL);
142 AdjustControlSize(IDC_PUSHALL);
143 AdjustControlSize(IDC_FORCE);
144 AdjustControlSize(IDC_FORCE_WITH_LEASE);
145 AdjustControlSize(IDC_PACK);
146 AdjustControlSize(IDC_TAGS);
147 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD);
148 AdjustControlSize(IDC_PROC_PUSH_SET_PUSHBRANCH);
149 AdjustControlSize(IDC_PROC_PUSH_SET_PUSHREMOTE);
150 AdjustControlSize(IDC_PROC_PUSH_SET_UPSTREAM);
151 AdjustControlSize(IDC_STATIC_RECURSE_SUBMODULES);
153 CString sWindowTitle;
154 GetWindowText(sWindowTitle);
155 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
157 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(CAppUtils::IsSSHPutty());
159 EnableSaveRestore(_T("PushDlg"));
161 m_RemoteURL.SetCaseSensitive(TRUE);
162 m_RemoteURL.SetURLHistory(TRUE);
164 CString WorkingDir=g_Git.m_CurrentDir;
165 WorkingDir.Replace(_T(':'),_T('_'));
166 m_regPushAllRemotes = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Push\\") + WorkingDir + _T("\\AllRemotes"), FALSE);
167 m_bPushAllRemotes = m_regPushAllRemotes;
168 m_regPushAllBranches = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Push\\") + WorkingDir + _T("\\AllBranches"), FALSE);
169 m_bPushAllBranches = m_regPushAllBranches;
170 m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));
171 m_RemoteURL.EnableWindow(FALSE);
172 CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);
175 m_regThinPack = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Push\\") + WorkingDir + _T("\\ThinPack"), FALSE);
176 m_bPack = m_regThinPack;
177 this->m_regAutoLoad = CRegDWORD(CString(_T("Software\\TortoiseGit\\History\\PushDlgAutoLoad\\"))+WorkingDir,
178 m_bAutoLoad);
179 m_bAutoLoad = this->m_regAutoLoad;
180 if(!CAppUtils::IsSSHPutty())
181 m_bAutoLoad = false;
183 m_BrowseLocalRef.m_bRightArrow = TRUE;
184 m_BrowseLocalRef.m_bDefaultClick = FALSE;
185 m_BrowseLocalRef.m_bMarkDefault = FALSE;
186 m_BrowseLocalRef.AddEntry(CString(MAKEINTRESOURCE(IDS_REFBROWSE)));
187 m_BrowseLocalRef.AddEntry(CString(MAKEINTRESOURCE(IDS_LOG)));
188 m_BrowseLocalRef.AddEntry(CString(MAKEINTRESOURCE(IDS_REFLOG)));
190 m_tooltips.Create(this);
191 m_tooltips.AddTool(IDC_PROC_PUSH_SET_PUSHBRANCH, IDS_PUSHDLG_PUSHBRANCH_TT);
192 m_tooltips.AddTool(IDC_PROC_PUSH_SET_PUSHREMOTE, IDS_PUSHDLG_PUSHREMOTE_TT);
193 m_tooltips.AddTool(IDC_FORCE, IDS_FORCE_TT);
194 m_tooltips.AddTool(IDC_FORCE_WITH_LEASE, IDS_FORCE_WITH_LEASE_TT);
196 m_regRecurseSubmodules = CRegDWORD(
197 CString(_T("Software\\TortoiseGit\\History\\PushRecurseSubmodules\\")) + WorkingDir, m_RecurseSubmodules);
198 m_RecurseSubmodules = m_regRecurseSubmodules;
199 m_RecurseSubmodulesCombo.AddString(CString(MAKEINTRESOURCE(IDS_NONE)));
200 m_RecurseSubmodulesCombo.AddString(CString(MAKEINTRESOURCE(IDS_RECURSE_SUBMODULES_CHECK)));
201 m_RecurseSubmodulesCombo.AddString(CString(MAKEINTRESOURCE(IDS_RECURSE_SUBMODULES_ONDEMAND)));
202 m_RecurseSubmodulesCombo.SetCurSel(m_RecurseSubmodules);
204 if (CAppUtils::GetMsysgitVersion() < 0x01080500)
205 GetDlgItem(IDC_FORCE_WITH_LEASE)->EnableWindow(FALSE);
207 Refresh();
209 this->UpdateData(false);
211 OnBnClickedPushall();
212 return TRUE;
215 void CPushDlg::Refresh()
217 CString WorkingDir=g_Git.m_CurrentDir;
218 WorkingDir.Replace(_T(':'),_T('_'));
220 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
221 m_RemoteReg = remote;
222 int sel = -1;
224 STRING_VECTOR list;
225 m_Remote.Reset();
227 if(!g_Git.GetRemoteList(list))
229 if (list.size() > 1)
230 m_Remote.AddString(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)));
231 for (unsigned int i = 0; i < list.size(); ++i)
233 m_Remote.AddString(list[i]);
234 if(list[i] == remote)
235 sel = i + (list.size() > 1 ? 1 : 0);
238 else
239 MessageBox(g_Git.GetGitLastErr(_T("Could not get list of remotes.")), _T("TortoiseGit"), MB_ICONERROR);
240 // if the last selected remote was "- All -" and "- All -" is still in the list -> select it
241 if (list.size() > 1 && remote == CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)))
242 sel = 0;
243 m_Remote.SetCurSel(sel);
245 int current = -1;
246 list.clear();
247 m_BranchSource.Reset();
248 m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
249 if(!g_Git.GetBranchList(list,&current))
250 m_BranchSource.SetList(list);
251 else
252 MessageBox(g_Git.GetGitLastErr(_T("Could not get list of local branches.")), _T("TortoiseGit"), MB_ICONERROR);
253 if (wcsncmp(m_BranchSourceName, _T("refs/"), 5) == 0)
254 m_BranchSourceName = m_BranchSourceName.Mid(5);
255 if (wcsncmp(m_BranchSourceName, _T("heads/"), 6) == 0)
257 m_BranchSourceName = m_BranchSourceName.Mid(6);
258 m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
260 else if (wcsncmp(m_BranchSourceName, _T("remotes/"), 8) == 0)
261 m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
262 else
263 m_BranchSource.SetCurSel(current);
265 GetRemoteBranch(m_BranchSource.GetString());
267 this->GetDlgItem(IDOK)->EnableWindow(m_BranchSource.GetCount() != 0);
269 if (list.size() > 1 && m_bPushAllRemotes)
270 m_Remote.SetCurSel(0);
271 m_bPushAllRemotes = FALSE; // reset to FALSE, so that a refresh does not reselect all even if it was already deselected by user; correct value will be set in OnBnClickedOk method
274 void CPushDlg::GetRemoteBranch(CString currentBranch)
276 CString WorkingDir=g_Git.m_CurrentDir;
277 WorkingDir.Replace(_T(':'), _T('_'));
279 if (currentBranch.IsEmpty())
281 EnDisablePushRemoteArchiveBranch();
282 return;
285 CString configName;
287 configName.Format(L"branch.%s.pushremote", currentBranch);
288 CString pushRemote = g_Git.GetConfigValue(configName);
289 if( pushRemote.IsEmpty() )
291 pushRemote = g_Git.GetConfigValue(L"remote.pushdefault");
292 if (pushRemote.IsEmpty())
294 configName.Format(L"branch.%s.remote", currentBranch);
295 pushRemote = g_Git.GetConfigValue(configName);
299 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
301 if (!pushRemote.IsEmpty())
303 remote = pushRemote;
304 // if a pushRemote exists, select it
305 for (int i = 0; i < m_Remote.GetCount(); ++i)
307 CString str;
308 int n = m_Remote.GetLBTextLen(i);
309 m_Remote.GetLBText(i, str.GetBuffer(n));
310 str.ReleaseBuffer();
311 if (str == pushRemote)
313 m_Remote.SetCurSel(i);
314 break;
318 // select the only remote if only one exists
319 else if (m_Remote.GetCount() == 1)
320 m_Remote.SetCurSel(0);
321 // select no remote if no push-remote is specified AND push to all remotes is not selected
322 else if (!(m_Remote.GetCount() > 1 && m_Remote.GetCurSel() == 0))
324 m_Remote.SetCurSel(-1);
327 //Select pull-branch from current branch
328 configName.Format(L"branch.%s.pushbranch", currentBranch);
329 CString pushBranch = g_Git.GetConfigValue(configName); // do not strip branch name (for gerrit), see issue #1609)
330 if( pushBranch.IsEmpty() )
332 configName.Format(L"branch.%s.merge", currentBranch);
333 pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
336 m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));
337 if( !pushBranch.IsEmpty() )
338 m_BranchRemote.AddString(pushBranch);
340 EnDisablePushRemoteArchiveBranch();
343 void CPushDlg::EnDisablePushRemoteArchiveBranch()
345 if ((m_Remote.GetCount() > 1 && m_Remote.GetCurSel() == 0) || m_bPushAllBranches || GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL || m_BranchSource.GetString().Trim().IsEmpty())
347 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHBRANCH, FALSE);
348 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHREMOTE, FALSE);
349 bool enableUpstream = (GetCheckedRadioButton(IDC_RD_REMOTE, IDC_RD_URL) != IDC_RD_URL && (!m_BranchSource.GetString().Trim().IsEmpty() || m_bPushAllBranches));
350 DialogEnableWindow(IDC_PROC_PUSH_SET_UPSTREAM, enableUpstream);
351 if (m_bSetUpstream && !enableUpstream)
352 m_bSetUpstream = FALSE;
353 m_bSetPushRemote = FALSE;
354 m_bSetPushBranch = FALSE;
355 UpdateData(FALSE);
357 else
359 DialogEnableWindow(IDC_PROC_PUSH_SET_UPSTREAM, TRUE);
360 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHBRANCH, !m_bSetUpstream);
361 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHREMOTE, !m_bSetUpstream);
365 // CPushDlg message handlers
367 void CPushDlg::OnBnClickedRd()
369 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
371 m_Remote.EnableWindow(TRUE);
372 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(TRUE);
373 m_RemoteURL.EnableWindow(FALSE);
375 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
377 CString clippath = CAppUtils::GetClipboardLink();
378 if (clippath.IsEmpty())
379 m_RemoteURL.SetCurSel(0);
380 else
381 m_RemoteURL.SetWindowText(clippath);
382 m_Remote.EnableWindow(FALSE);
383 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(FALSE);
384 m_RemoteURL.EnableWindow(TRUE);
386 EnDisablePushRemoteArchiveBranch();
390 void CPushDlg::OnCbnSelchangeBranchSource()
392 GetRemoteBranch(m_BranchSource.GetString());
395 void CPushDlg::OnBnClickedOk()
397 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
399 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
401 m_URL=m_Remote.GetString();
402 if (m_URL.IsEmpty())
404 CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_REMOTEEMPTY, IDS_APPNAME, MB_OK);
405 return;
407 m_bPushAllRemotes = (m_Remote.GetCurSel() == 0 && m_Remote.GetCount() > 1);
409 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
411 m_URL=m_RemoteURL.GetString();
414 if (!m_bPushAllBranches)
416 this->m_BranchRemoteName=m_BranchRemote.GetString().Trim();
417 this->m_BranchSourceName=m_BranchSource.GetString().Trim();
419 if (m_BranchSourceName.IsEmpty() && m_BranchRemoteName.IsEmpty())
421 if (CMessageBox::Show(NULL, IDS_B_T_BOTHEMPTY, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO) == IDNO)
422 return;
424 if (m_BranchSourceName.IsEmpty() && !m_BranchRemoteName.IsEmpty())
426 if (CMessageBox::Show(NULL, IDS_B_T_LOCALEMPTY, IDS_APPNAME, MB_ICONEXCLAMATION | MB_YESNO) == IDNO)
427 return;
429 else if (!m_BranchRemoteName.IsEmpty() && !g_Git.IsBranchNameValid(this->m_BranchRemoteName))
431 CMessageBox::Show(NULL, IDS_B_T_INVALID, IDS_APPNAME, MB_OK);
432 return;
434 else if (!m_BranchSourceName.IsEmpty() && !g_Git.IsBranchTagNameUnique(m_BranchSourceName))
436 CMessageBox::Show(NULL, IDS_B_T_NOT_UNIQUE, IDS_APPNAME, MB_OK | MB_ICONEXCLAMATION);
437 return;
439 else
441 // do not store branch names on removal
442 if (m_RemoteURL.IsWindowEnabled())
443 m_RemoteURL.SaveHistory(); // do not store Remote URLs if not used
444 this->m_BranchRemote.SaveHistory();
445 m_RemoteReg = m_Remote.GetString();
447 if (!m_BranchSourceName.IsEmpty())
449 CString configName;
450 if (m_bSetPushBranch)
452 configName.Format(L"branch.%s.pushbranch", m_BranchSourceName);
453 if (!m_BranchRemoteName.IsEmpty())
454 g_Git.SetConfigValue(configName, m_BranchRemoteName);
455 else
456 g_Git.UnsetConfigValue(configName);
458 if (m_bSetPushRemote)
460 configName.Format(L"branch.%s.pushremote", m_BranchSourceName);
461 if (!m_URL.IsEmpty())
462 g_Git.SetConfigValue(configName, m_URL);
463 else
464 g_Git.UnsetConfigValue(configName);
470 m_regPushAllBranches = m_bPushAllBranches;
471 m_regPushAllRemotes = m_bPushAllRemotes;
472 m_regThinPack = m_bPack;
473 this->m_regAutoLoad = m_bAutoLoad ;
474 m_RecurseSubmodules = m_RecurseSubmodulesCombo.GetCurSel();
475 if (m_RecurseSubmodules == 2 && CAppUtils::GetMsysgitVersion() < 0x01070b00)
477 CString gitver;
478 gitver.Format(IDS_GITVER_REQUIRED, _T("--recurse-submodules=on-demand"), _T("1.7.11"));
479 CMessageBox::Show(m_hWnd, gitver, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
480 return;
482 m_regRecurseSubmodules = m_RecurseSubmodules;
484 CHorizontalResizableStandAloneDialog::OnOK();
487 void CPushDlg::OnBnClickedRemoteManage()
489 CAppUtils::LaunchRemoteSetting();
490 Refresh();
493 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
495 switch (m_BrowseLocalRef.GetCurrentEntry())
497 case 0: /* Browse Refence*/
499 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))
500 OnCbnSelchangeBranchSource();
502 break;
504 case 1: /* Log */
506 CLogDlg dlg;
507 dlg.SetSelect(true);
508 if(dlg.DoModal() == IDOK)
510 if (dlg.GetSelectedHash().IsEmpty())
511 return;
513 m_BranchSource.SetWindowText(dlg.GetSelectedHash());
514 OnCbnSelchangeBranchSource();
517 break;
519 case 2: /*RefLog*/
521 CRefLogDlg dlg;
522 if(dlg.DoModal() == IDOK)
524 m_BranchSource.SetWindowText(dlg.m_SelectedHash);
525 OnCbnSelchangeBranchSource();
528 break;
532 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
534 CString remoteBranchName;
535 CString remoteName;
536 m_BranchRemote.GetWindowText(remoteBranchName);
537 remoteName = m_Remote.GetString();
538 remoteBranchName = remoteName + '/' + remoteBranchName;
539 remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);
540 if(remoteBranchName.IsEmpty())
541 return; //Canceled
542 remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'
543 int slashPlace = remoteBranchName.Find('/');
544 remoteName = remoteBranchName.Left(slashPlace);
545 remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')
547 //Select remote
548 int remoteSel = m_Remote.FindStringExact(0,remoteName);
549 if(remoteSel >= 0)
550 m_Remote.SetCurSel(remoteSel);
552 //Select branch
553 m_BranchRemote.AddString(remoteBranchName, 0);
556 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)
558 m_tooltips.RelayEvent(pMsg);
560 if (pMsg->message == WM_KEYDOWN)
562 switch (pMsg->wParam)
564 case VK_F5:
566 Refresh();
568 break;
572 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
575 void CPushDlg::OnBnClickedPushall()
577 this->UpdateData();
578 this->GetDlgItem(IDC_BRANCH_REMOTE)->EnableWindow(!m_bPushAllBranches);
579 this->GetDlgItem(IDC_BRANCH_SOURCE)->EnableWindow(!m_bPushAllBranches);
580 this->GetDlgItem(IDC_BUTTON_BROWSE_SOURCE_BRANCH)->EnableWindow(!m_bPushAllBranches);
581 this->GetDlgItem(IDC_BUTTON_BROWSE_DEST_BRANCH)->EnableWindow(!m_bPushAllBranches);
582 EnDisablePushRemoteArchiveBranch();
585 void CPushDlg::OnBnClickedForce()
587 UpdateData();
588 if (CAppUtils::GetMsysgitVersion() >= 0x01080500)
589 GetDlgItem(IDC_FORCE_WITH_LEASE)->EnableWindow(m_bForce ? FALSE : TRUE);
592 void CPushDlg::OnBnClickedForceWithLease()
594 UpdateData();
595 GetDlgItem(IDC_FORCE)->EnableWindow(m_bForceWithLease ? FALSE : TRUE);
598 void CPushDlg::OnBnClickedProcPushSetUpstream()
600 UpdateData();
601 this->GetDlgItem(IDC_PROC_PUSH_SET_PUSHREMOTE)->EnableWindow(!m_bSetUpstream);
602 this->GetDlgItem(IDC_PROC_PUSH_SET_PUSHBRANCH)->EnableWindow(!m_bSetUpstream);
603 m_bSetPushBranch = FALSE;
604 m_bSetPushRemote = FALSE;
605 UpdateData(FALSE);
608 void CPushDlg::OnBnClickedProcPushSetPushremote()
610 UpdateData();
611 this->GetDlgItem(IDC_PROC_PUSH_SET_UPSTREAM)->EnableWindow(!(m_bSetPushBranch || m_bSetPushRemote));
612 m_bSetUpstream = FALSE;
613 UpdateData(FALSE);