Don't import ogdf namespace
[TortoiseGit.git] / src / TortoiseProc / PushDlg.cpp
bloba69ae6032c8b5981d161244230b2702775799bd8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2018 - 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"
26 #include "StringUtils.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 /*=nullptr*/)
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_bPushAllRemotes(FALSE)
47 , m_bSetPushBranch(FALSE)
48 , m_bSetPushRemote(FALSE)
49 , m_bSetUpstream(FALSE)
50 , m_RecurseSubmodules(0)
51 , m_bAutoLoad(CAppUtils::IsSSHPutty())
55 CPushDlg::~CPushDlg()
59 void CPushDlg::DoDataExchange(CDataExchange* pDX)
61 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX);
62 DDX_Control(pDX, IDC_BRANCH_REMOTE, this->m_BranchRemote);
63 DDX_Control(pDX, IDC_BRANCH_SOURCE, this->m_BranchSource);
64 DDX_Control(pDX, IDC_REMOTE, this->m_Remote);
65 DDX_Control(pDX, IDC_URL, this->m_RemoteURL);
66 DDX_Control(pDX, IDC_BUTTON_BROWSE_SOURCE_BRANCH, m_BrowseLocalRef);
67 DDX_Control(pDX, IDC_COMBOBOX_RECURSE_SUBMODULES, m_RecurseSubmodulesCombo);
68 DDX_Check(pDX,IDC_FORCE,this->m_bForce);
69 DDX_Check(pDX, IDC_FORCE_WITH_LEASE, m_bForceWithLease);
70 DDX_Check(pDX,IDC_PUSHALL,this->m_bPushAllBranches);
71 DDX_Check(pDX,IDC_PACK,this->m_bPack);
72 DDX_Check(pDX,IDC_TAGS,this->m_bTags);
73 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,this->m_bAutoLoad);
74 DDX_Check(pDX, IDC_PROC_PUSH_SET_PUSHREMOTE, m_bSetPushRemote);
75 DDX_Check(pDX, IDC_PROC_PUSH_SET_PUSHBRANCH, m_bSetPushBranch);
76 DDX_Check(pDX, IDC_PROC_PUSH_SET_UPSTREAM, m_bSetUpstream);
79 BEGIN_MESSAGE_MAP(CPushDlg, CHorizontalResizableStandAloneDialog)
80 ON_BN_CLICKED(IDC_RD_REMOTE, &CPushDlg::OnBnClickedRd)
81 ON_BN_CLICKED(IDC_RD_URL, &CPushDlg::OnBnClickedRd)
82 ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE, &CPushDlg::OnCbnSelchangeBranchSource)
83 ON_CBN_SELCHANGE(IDC_REMOTE, &CPushDlg::EnDisablePushRemoteArchiveBranch)
84 ON_BN_CLICKED(IDOK, &CPushDlg::OnBnClickedOk)
85 ON_BN_CLICKED(IDC_REMOTE_MANAGE, &CPushDlg::OnBnClickedRemoteManage)
86 ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH, &CPushDlg::OnBnClickedButtonBrowseSourceBranch)
87 ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH, &CPushDlg::OnBnClickedButtonBrowseDestBranch)
88 ON_BN_CLICKED(IDC_PUSHALL, &CPushDlg::OnBnClickedPushall)
89 ON_BN_CLICKED(IDC_FORCE, &CPushDlg::OnBnClickedForce)
90 ON_BN_CLICKED(IDC_FORCE_WITH_LEASE, &CPushDlg::OnBnClickedForceWithLease)
91 ON_BN_CLICKED(IDC_TAGS, &CPushDlg::OnBnClickedTags)
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 AdjustControlSize(IDC_RD_REMOTE);
103 AdjustControlSize(IDC_RD_URL);
104 AdjustControlSize(IDC_PUSHALL);
105 AdjustControlSize(IDC_FORCE);
106 AdjustControlSize(IDC_FORCE_WITH_LEASE);
107 AdjustControlSize(IDC_PACK);
108 AdjustControlSize(IDC_TAGS);
109 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD);
110 AdjustControlSize(IDC_PROC_PUSH_SET_PUSHBRANCH);
111 AdjustControlSize(IDC_PROC_PUSH_SET_PUSHREMOTE);
112 AdjustControlSize(IDC_PROC_PUSH_SET_UPSTREAM);
113 AdjustControlSize(IDC_STATIC_RECURSE_SUBMODULES);
115 AddAnchor(IDOK,BOTTOM_RIGHT);
116 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
117 AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);
118 AddAnchor(IDC_STATIC_REMOTE, TOP_LEFT);
119 AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);
121 AddAnchor(IDC_PUSHALL, TOP_LEFT);
122 AddAnchor(IDC_BRANCH_REMOTE, TOP_LEFT, TOP_RIGHT);
123 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);
124 AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT, TOP_RIGHT);
125 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_RIGHT);
127 AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);
128 AddAnchor(IDC_RD_REMOTE, TOP_LEFT);
129 AddAnchor(IDC_RD_URL, TOP_LEFT);
131 AddAnchor(IDC_REMOTE, TOP_LEFT, TOP_RIGHT);
133 AddAnchor(IDC_URL, TOP_LEFT,TOP_RIGHT);
135 AddAnchor(IDC_OPTION_GROUP, TOP_LEFT,TOP_RIGHT);
137 AddAnchor(IDC_FORCE, TOP_LEFT);
138 AddAnchor(IDC_FORCE_WITH_LEASE, TOP_LEFT);
139 AddAnchor(IDC_PACK, TOP_LEFT);
140 AddAnchor(IDC_TAGS, TOP_LEFT);
141 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);
142 AddAnchor(IDC_PROC_PUSH_SET_PUSHBRANCH, TOP_LEFT);
143 AddAnchor(IDC_PROC_PUSH_SET_PUSHREMOTE, TOP_LEFT);
144 AddAnchor(IDC_PROC_PUSH_SET_UPSTREAM, TOP_LEFT);
145 AddAnchor(IDC_STATIC_RECURSE_SUBMODULES, TOP_LEFT);
146 AddAnchor(IDC_COMBOBOX_RECURSE_SUBMODULES, TOP_LEFT);
148 AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);
149 AddAnchor(IDHELP, BOTTOM_RIGHT);
151 AddOthersToAnchor();
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(L"PushDlg");
161 m_Remote.SetMaxHistoryItems(0x7FFFFFFF);
162 m_RemoteURL.SetCaseSensitive(TRUE);
163 m_RemoteURL.SetURLHistory(TRUE);
165 CString WorkingDir=g_Git.m_CurrentDir;
166 WorkingDir.Replace(L':', L'_');
167 m_regPushAllRemotes = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\Push\\" + WorkingDir + L"\\AllRemotes", FALSE);
168 m_bPushAllRemotes = m_regPushAllRemotes;
169 m_regPushAllBranches = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\Push\\" + WorkingDir + L"\\AllBranches", FALSE);
170 m_bPushAllBranches = m_regPushAllBranches;
171 m_RemoteURL.LoadHistory(L"Software\\TortoiseGit\\History\\PushURLS\\" + WorkingDir, L"url");
172 m_RemoteURL.EnableWindow(FALSE);
173 CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);
176 m_regThinPack = CRegDWORD(L"Software\\TortoiseGit\\TortoiseProc\\Push\\" + WorkingDir + L"\\ThinPack", FALSE);
177 m_bPack = m_regThinPack;
178 this->m_regAutoLoad = CRegDWORD(L"Software\\TortoiseGit\\History\\PushDlgAutoLoad\\" + WorkingDir,
179 m_bAutoLoad);
180 m_bAutoLoad = this->m_regAutoLoad;
181 if(!CAppUtils::IsSSHPutty())
182 m_bAutoLoad = false;
184 m_BrowseLocalRef.m_bRightArrow = TRUE;
185 m_BrowseLocalRef.m_bDefaultClick = FALSE;
186 m_BrowseLocalRef.m_bMarkDefault = FALSE;
187 m_BrowseLocalRef.m_bShowCurrentItem = FALSE;
188 m_BrowseLocalRef.AddEntry(CString(MAKEINTRESOURCE(IDS_REFBROWSE)));
189 m_BrowseLocalRef.AddEntry(CString(MAKEINTRESOURCE(IDS_LOG)));
190 m_BrowseLocalRef.AddEntry(CString(MAKEINTRESOURCE(IDS_REFLOG)));
192 m_tooltips.AddTool(IDC_PROC_PUSH_SET_PUSHBRANCH, IDS_PUSHDLG_PUSHBRANCH_TT);
193 m_tooltips.AddTool(IDC_PROC_PUSH_SET_PUSHREMOTE, IDS_PUSHDLG_PUSHREMOTE_TT);
194 m_tooltips.AddTool(IDC_FORCE, IDS_FORCE_TT);
195 m_tooltips.AddTool(IDC_FORCE_WITH_LEASE, IDS_FORCE_WITH_LEASE_TT);
197 CString recurseSubmodules = g_Git.GetConfigValue(L"push.recurseSubmodules");
198 if (recurseSubmodules == L"check")
199 m_RecurseSubmodules = 1;
200 else if (recurseSubmodules == L"on-demand")
201 m_RecurseSubmodules = 2;
202 else
203 m_RecurseSubmodules = 0;
204 m_regRecurseSubmodules = CRegDWORD(L"Software\\TortoiseGit\\History\\PushRecurseSubmodules\\" + WorkingDir, m_RecurseSubmodules);
205 m_RecurseSubmodules = m_regRecurseSubmodules;
206 m_RecurseSubmodulesCombo.AddString(CString(MAKEINTRESOURCE(IDS_NONE)));
207 m_RecurseSubmodulesCombo.AddString(CString(MAKEINTRESOURCE(IDS_RECURSE_SUBMODULES_CHECK)));
208 m_RecurseSubmodulesCombo.AddString(CString(MAKEINTRESOURCE(IDS_RECURSE_SUBMODULES_ONDEMAND)));
209 m_RecurseSubmodulesCombo.SetCurSel(m_RecurseSubmodules);
211 Refresh();
213 this->UpdateData(false);
215 OnBnClickedPushall();
216 return TRUE;
219 void CPushDlg::Refresh()
221 CString WorkingDir=g_Git.m_CurrentDir;
222 WorkingDir.Replace(L':', L'_');
224 CRegString remote(L"Software\\TortoiseGit\\History\\PushRemote\\" + WorkingDir);
225 m_RemoteReg = remote;
226 int sel = -1;
228 STRING_VECTOR list;
229 m_Remote.Reset();
231 if(!g_Git.GetRemoteList(list))
233 if (list.size() > 1)
234 m_Remote.AddString(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)));
235 for (unsigned int i = 0; i < list.size(); ++i)
237 m_Remote.AddString(list[i]);
238 if(list[i] == remote)
239 sel = i + (list.size() > 1 ? 1 : 0);
242 else
243 MessageBox(g_Git.GetGitLastErr(L"Could not get list of remotes."), L"TortoiseGit", MB_ICONERROR);
244 // if the last selected remote was "- All -" and "- All -" is still in the list -> select it
245 if (list.size() > 1 && remote == CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)))
246 sel = 0;
247 m_Remote.SetCurSel(sel);
249 int current = -1;
250 list.clear();
251 m_BranchSource.Reset();
252 m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
253 if(!g_Git.GetBranchList(list,&current))
254 m_BranchSource.SetList(list);
255 else
256 MessageBox(g_Git.GetGitLastErr(L"Could not get list of local branches."), L"TortoiseGit", MB_ICONERROR);
257 if (CStringUtils::StartsWith(m_BranchSourceName, L"refs/heads/"))
259 m_BranchSourceName = m_BranchSourceName.Mid((int)wcslen(L"refs/heads/"));
260 m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
262 else if (CStringUtils::StartsWith(m_BranchSourceName, L"refs/remotes/") || CStringUtils::StartsWith(m_BranchSourceName, L"remotes/"))
264 if (CStringUtils::StartsWith(m_BranchSourceName, L"refs/"))
265 m_BranchSourceName = m_BranchSourceName.Mid((int)wcslen(L"refs/"));
266 m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
268 else if (m_BranchSourceName.IsEmpty() && current == -1 && !g_Git.IsInitRepos())
269 m_BranchSource.SetWindowText(L"HEAD");
270 else if (m_BranchSourceName.IsEmpty())
271 m_BranchSource.SetCurSel(current);
272 else
273 m_BranchSource.SetWindowText(m_BranchSourceName);
275 GetRemoteBranch(m_BranchSource.GetString());
277 if (list.size() > 1 && m_bPushAllRemotes)
278 m_Remote.SetCurSel(0);
279 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
282 void CPushDlg::GetRemoteBranch(CString currentBranch)
284 CString WorkingDir=g_Git.m_CurrentDir;
285 WorkingDir.Replace(L':', L'_');
287 if (currentBranch.IsEmpty())
289 EnDisablePushRemoteArchiveBranch();
290 return;
293 CString pushRemote;
294 CString pushBranch;
295 g_Git.GetRemotePushBranch(currentBranch, pushRemote, pushBranch);
297 CRegString remote(L"Software\\TortoiseGit\\History\\PushRemote\\" + WorkingDir);
299 if (!pushRemote.IsEmpty())
301 remote = pushRemote;
302 // if a pushRemote exists, select it
303 for (int i = 0; i < m_Remote.GetCount(); ++i)
305 CString str;
306 int n = m_Remote.GetLBTextLen(i);
307 m_Remote.GetLBText(i, CStrBuf(str, n));
308 if (str == pushRemote)
310 m_Remote.SetCurSel(i);
311 break;
315 // select the only remote if only one exists
316 else if (m_Remote.GetCount() == 1)
317 m_Remote.SetCurSel(0);
318 // select no remote if no push-remote is specified AND push to all remotes is not selected
319 else if (!(m_Remote.GetCount() > 1 && m_Remote.GetCurSel() == 0))
320 m_Remote.SetCurSel(-1);
322 m_BranchRemote.LoadHistory(L"Software\\TortoiseGit\\History\\RemoteBranch\\" + WorkingDir, L"branch");
323 if( !pushBranch.IsEmpty() )
324 m_BranchRemote.AddString(pushBranch);
326 EnDisablePushRemoteArchiveBranch();
329 void CPushDlg::EnDisablePushRemoteArchiveBranch()
331 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())
333 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHBRANCH, FALSE);
334 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHREMOTE, FALSE);
335 bool enableUpstream = (GetCheckedRadioButton(IDC_RD_REMOTE, IDC_RD_URL) != IDC_RD_URL && (!m_BranchSource.GetString().Trim().IsEmpty() || m_bPushAllBranches));
336 DialogEnableWindow(IDC_PROC_PUSH_SET_UPSTREAM, enableUpstream);
337 if (m_bSetUpstream && !enableUpstream)
338 m_bSetUpstream = FALSE;
339 m_bSetPushRemote = FALSE;
340 m_bSetPushBranch = FALSE;
341 UpdateData(FALSE);
343 else
345 DialogEnableWindow(IDC_PROC_PUSH_SET_UPSTREAM, TRUE);
346 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHBRANCH, !m_bSetUpstream);
347 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHREMOTE, !m_bSetUpstream);
351 // CPushDlg message handlers
353 void CPushDlg::OnBnClickedRd()
355 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
357 m_Remote.EnableWindow(TRUE);
358 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(TRUE);
359 m_RemoteURL.EnableWindow(FALSE);
361 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
363 CString clippath = CAppUtils::GetClipboardLink();
364 if (clippath.IsEmpty())
365 m_RemoteURL.SetCurSel(0);
366 else
367 m_RemoteURL.SetWindowText(clippath);
368 m_Remote.EnableWindow(FALSE);
369 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(FALSE);
370 m_RemoteURL.EnableWindow(TRUE);
372 EnDisablePushRemoteArchiveBranch();
376 void CPushDlg::OnCbnSelchangeBranchSource()
378 GetRemoteBranch(m_BranchSource.GetString());
381 void CPushDlg::OnBnClickedOk()
383 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
385 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
387 m_URL=m_Remote.GetString();
388 if (m_URL.IsEmpty())
390 CMessageBox::Show(GetSafeHwnd(), IDS_PROC_GITCONFIG_REMOTEEMPTY, IDS_APPNAME, MB_OK | MB_ICONEXCLAMATION);
391 return;
393 m_bPushAllRemotes = (m_Remote.GetCurSel() == 0 && m_Remote.GetCount() > 1);
395 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
396 m_URL=m_RemoteURL.GetString();
398 if (m_bPushAllBranches)
400 BOOL dontaskagainchecked = FALSE;
401 if (CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_PUSH_ALLBRANCHES, IDS_APPNAME, MB_ICONQUESTION | MB_DEFBUTTON2 | MB_YESNO, L"PushAllBranches", IDS_MSGBOX_DONOTSHOWAGAIN, &dontaskagainchecked) == IDNO)
403 if (dontaskagainchecked)
404 CMessageBox::SetRegistryValue(L"PushAllBranches", IDYES);
405 return;
408 else
410 this->m_BranchRemoteName=m_BranchRemote.GetString().Trim();
411 this->m_BranchSourceName=m_BranchSource.GetString().Trim();
413 if (m_BranchSourceName.IsEmpty() && m_BranchRemoteName.IsEmpty())
415 if (CMessageBox::Show(GetSafeHwnd(), IDS_B_T_BOTHEMPTY, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO) != IDYES)
416 return;
418 if (m_BranchSourceName.IsEmpty() && !m_BranchRemoteName.IsEmpty())
420 if (CMessageBox::Show(GetSafeHwnd(), IDS_B_T_LOCALEMPTY, IDS_APPNAME, MB_ICONEXCLAMATION | MB_YESNO) != IDYES)
421 return;
423 else if (!m_BranchRemoteName.IsEmpty() && !g_Git.IsBranchNameValid(this->m_BranchRemoteName))
425 CMessageBox::Show(GetSafeHwnd(), IDS_B_T_INVALID, IDS_APPNAME, MB_OK | MB_ICONEXCLAMATION);
426 return;
428 else if (!m_BranchSourceName.IsEmpty() && !g_Git.IsBranchTagNameUnique(m_BranchSourceName))
430 CMessageBox::Show(GetSafeHwnd(), IDS_B_T_NOT_UNIQUE, IDS_APPNAME, MB_OK | MB_ICONEXCLAMATION);
431 return;
433 else
435 // do not store branch names on removal
436 if (m_RemoteURL.IsWindowEnabled())
437 m_RemoteURL.SaveHistory(); // do not store Remote URLs if not used
438 this->m_BranchRemote.SaveHistory();
439 m_RemoteReg = m_Remote.GetString();
441 if (!m_BranchSourceName.IsEmpty() && g_Git.IsLocalBranch(m_BranchSourceName))
443 CString configName;
444 if (m_bSetPushBranch)
446 configName.Format(L"branch.%s.pushbranch", (LPCTSTR)m_BranchSourceName);
447 if (!m_BranchRemoteName.IsEmpty())
448 g_Git.SetConfigValue(configName, m_BranchRemoteName);
449 else
450 g_Git.UnsetConfigValue(configName);
452 if (m_bSetPushRemote)
454 configName.Format(L"branch.%s.pushremote", (LPCTSTR)m_BranchSourceName);
455 if (!m_URL.IsEmpty())
456 g_Git.SetConfigValue(configName, m_URL);
457 else
458 g_Git.UnsetConfigValue(configName);
464 m_regPushAllBranches = m_bPushAllBranches;
465 m_regPushAllRemotes = m_bPushAllRemotes;
466 m_regThinPack = m_bPack;
467 this->m_regAutoLoad = m_bAutoLoad ;
468 m_RecurseSubmodules = m_RecurseSubmodulesCombo.GetCurSel();
469 m_regRecurseSubmodules = m_RecurseSubmodules;
471 CHorizontalResizableStandAloneDialog::OnOK();
474 void CPushDlg::OnBnClickedRemoteManage()
476 CAppUtils::LaunchRemoteSetting();
477 Refresh();
480 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
482 switch (m_BrowseLocalRef.GetCurrentEntry())
484 case 0: /* Browse Refence*/
486 if (CBrowseRefsDlg::PickRefForCombo(m_BranchSource, gPickRef_Head | gPickRef_Tag))
487 OnCbnSelchangeBranchSource();
489 break;
491 case 1: /* Log */
493 CLogDlg dlg;
494 CString revision;
495 m_BranchSource.GetWindowText(revision);
496 dlg.SetParams(CTGitPath(), CTGitPath(), revision, revision, 0);
497 dlg.SetSelect(true);
498 dlg.ShowWorkingTreeChanges(false);
499 if (dlg.DoModal() == IDOK && !dlg.GetSelectedHash().empty())
501 m_BranchSource.SetWindowText(dlg.GetSelectedHash().at(0).ToString());
502 OnCbnSelchangeBranchSource();
505 break;
507 case 2: /*RefLog*/
509 CRefLogDlg dlg;
510 if(dlg.DoModal() == IDOK)
512 m_BranchSource.SetWindowText(dlg.m_SelectedHash.ToString());
513 OnCbnSelchangeBranchSource();
516 break;
520 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
522 CString remoteBranchName;
523 CString remoteName;
524 m_BranchRemote.GetWindowText(remoteBranchName);
525 remoteName = m_Remote.GetString();
526 remoteBranchName = remoteName + '/' + remoteBranchName;
527 remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);
528 if(remoteBranchName.IsEmpty())
529 return; //Canceled
530 remoteBranchName = remoteBranchName.Mid((int)wcslen(L"refs/remotes/")); //Strip 'refs/remotes/'
531 int slashPlace = remoteBranchName.Find('/');
532 remoteName = remoteBranchName.Left(slashPlace);
533 remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')
535 //Select remote
536 int remoteSel = m_Remote.FindStringExact(0,remoteName);
537 if(remoteSel >= 0)
538 m_Remote.SetCurSel(remoteSel);
540 //Select branch
541 m_BranchRemote.AddString(remoteBranchName, 0);
544 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)
546 if (pMsg->message == WM_KEYDOWN)
548 switch (pMsg->wParam)
550 case VK_F5:
552 Refresh();
554 break;
558 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
561 void CPushDlg::OnBnClickedPushall()
563 this->UpdateData();
564 this->GetDlgItem(IDC_BRANCH_REMOTE)->EnableWindow(!m_bPushAllBranches);
565 this->GetDlgItem(IDC_BRANCH_SOURCE)->EnableWindow(!m_bPushAllBranches);
566 this->GetDlgItem(IDC_BUTTON_BROWSE_SOURCE_BRANCH)->EnableWindow(!m_bPushAllBranches);
567 this->GetDlgItem(IDC_BUTTON_BROWSE_DEST_BRANCH)->EnableWindow(!m_bPushAllBranches);
568 EnDisablePushRemoteArchiveBranch();
571 void CPushDlg::OnBnClickedForce()
573 UpdateData();
574 GetDlgItem(IDC_FORCE_WITH_LEASE)->EnableWindow(m_bTags || m_bForce ? FALSE : TRUE);
577 void CPushDlg::OnBnClickedForceWithLease()
579 UpdateData();
580 GetDlgItem(IDC_FORCE)->EnableWindow(m_bForceWithLease ? FALSE : TRUE);
581 GetDlgItem(IDC_TAGS)->EnableWindow(m_bForceWithLease ? FALSE : TRUE);
584 void CPushDlg::OnBnClickedTags()
586 UpdateData();
587 GetDlgItem(IDC_FORCE_WITH_LEASE)->EnableWindow(m_bTags || m_bForce ? FALSE : TRUE);
590 void CPushDlg::OnBnClickedProcPushSetUpstream()
592 UpdateData();
593 this->GetDlgItem(IDC_PROC_PUSH_SET_PUSHREMOTE)->EnableWindow(!m_bSetUpstream);
594 this->GetDlgItem(IDC_PROC_PUSH_SET_PUSHBRANCH)->EnableWindow(!m_bSetUpstream);
595 m_bSetPushBranch = FALSE;
596 m_bSetPushRemote = FALSE;
597 UpdateData(FALSE);
600 void CPushDlg::OnBnClickedProcPushSetPushremote()
602 UpdateData();
603 this->GetDlgItem(IDC_PROC_PUSH_SET_UPSTREAM)->EnableWindow(!(m_bSetPushBranch || m_bSetPushRemote));
604 m_bSetUpstream = FALSE;
605 UpdateData(FALSE);