Make sure buffer is large enough for the nul terminator
[TortoiseGit.git] / src / TortoiseProc / PushDlg.cpp
blobb545864e04689e1d785493c5f9f9add9e9fb7011
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - 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_TAGS, &CPushDlg::OnBnClickedTags)
93 ON_BN_CLICKED(IDC_PROC_PUSH_SET_UPSTREAM, &CPushDlg::OnBnClickedProcPushSetUpstream)
94 ON_BN_CLICKED(IDC_PROC_PUSH_SET_PUSHREMOTE, &CPushDlg::OnBnClickedProcPushSetPushremote)
95 ON_BN_CLICKED(IDC_PROC_PUSH_SET_PUSHBRANCH, &CPushDlg::OnBnClickedProcPushSetPushremote)
96 END_MESSAGE_MAP()
98 BOOL CPushDlg::OnInitDialog()
100 CHorizontalResizableStandAloneDialog::OnInitDialog();
101 CAppUtils::MarkWindowAsUnpinnable(m_hWnd);
103 AddAnchor(IDOK,BOTTOM_RIGHT);
104 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
105 AddAnchor(IDC_BRANCH_GROUP, TOP_LEFT,TOP_RIGHT);
106 AddAnchor(IDC_STATIC_REMOTE, TOP_LEFT);
107 AddAnchor(IDC_STATIC_SOURCE, TOP_LEFT);
109 AddAnchor(IDC_PUSHALL, TOP_LEFT);
110 AddAnchor(IDC_BRANCH_REMOTE, TOP_LEFT, TOP_RIGHT);
111 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH, TOP_RIGHT);
112 AddAnchor(IDC_BRANCH_SOURCE, TOP_LEFT, TOP_RIGHT);
113 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH, TOP_RIGHT);
115 AddAnchor(IDC_URL_GROUP, TOP_LEFT,TOP_RIGHT);
116 AddAnchor(IDC_RD_REMOTE, TOP_LEFT);
117 AddAnchor(IDC_RD_URL, TOP_LEFT);
119 AddAnchor(IDC_REMOTE, TOP_LEFT, TOP_RIGHT);
121 AddAnchor(IDC_URL, TOP_LEFT,TOP_RIGHT);
123 AddAnchor(IDC_OPTION_GROUP, TOP_LEFT,TOP_RIGHT);
125 AddAnchor(IDC_FORCE, TOP_LEFT);
126 AddAnchor(IDC_FORCE_WITH_LEASE, TOP_LEFT);
127 AddAnchor(IDC_PACK, TOP_LEFT);
128 AddAnchor(IDC_TAGS, TOP_LEFT);
129 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,TOP_LEFT);
130 AddAnchor(IDC_PROC_PUSH_SET_PUSHBRANCH, TOP_LEFT);
131 AddAnchor(IDC_PROC_PUSH_SET_PUSHREMOTE, TOP_LEFT);
132 AddAnchor(IDC_PROC_PUSH_SET_UPSTREAM, TOP_LEFT);
133 AddAnchor(IDC_STATIC_RECURSE_SUBMODULES, TOP_LEFT);
134 AddAnchor(IDC_COMBOBOX_RECURSE_SUBMODULES, TOP_LEFT);
136 AddAnchor(IDC_REMOTE_MANAGE,TOP_RIGHT);
137 AddAnchor(IDHELP, BOTTOM_RIGHT);
139 AddOthersToAnchor();
141 AdjustControlSize(IDC_RD_REMOTE);
142 AdjustControlSize(IDC_RD_URL);
143 AdjustControlSize(IDC_PUSHALL);
144 AdjustControlSize(IDC_FORCE);
145 AdjustControlSize(IDC_FORCE_WITH_LEASE);
146 AdjustControlSize(IDC_PACK);
147 AdjustControlSize(IDC_TAGS);
148 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD);
149 AdjustControlSize(IDC_PROC_PUSH_SET_PUSHBRANCH);
150 AdjustControlSize(IDC_PROC_PUSH_SET_PUSHREMOTE);
151 AdjustControlSize(IDC_PROC_PUSH_SET_UPSTREAM);
152 AdjustControlSize(IDC_STATIC_RECURSE_SUBMODULES);
154 CString sWindowTitle;
155 GetWindowText(sWindowTitle);
156 CAppUtils::SetWindowTitle(m_hWnd, g_Git.m_CurrentDir, sWindowTitle);
158 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(CAppUtils::IsSSHPutty());
160 EnableSaveRestore(_T("PushDlg"));
162 m_Remote.SetMaxHistoryItems(0x7FFFFFFF);
163 m_RemoteURL.SetCaseSensitive(TRUE);
164 m_RemoteURL.SetURLHistory(TRUE);
166 CString WorkingDir=g_Git.m_CurrentDir;
167 WorkingDir.Replace(_T(':'),_T('_'));
168 m_regPushAllRemotes = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Push\\") + WorkingDir + _T("\\AllRemotes"), FALSE);
169 m_bPushAllRemotes = m_regPushAllRemotes;
170 m_regPushAllBranches = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Push\\") + WorkingDir + _T("\\AllBranches"), FALSE);
171 m_bPushAllBranches = m_regPushAllBranches;
172 m_RemoteURL.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir, _T("url"));
173 m_RemoteURL.EnableWindow(FALSE);
174 CheckRadioButton(IDC_RD_REMOTE,IDC_RD_URL,IDC_RD_REMOTE);
177 m_regThinPack = CRegDWORD(_T("Software\\TortoiseGit\\TortoiseProc\\Push\\") + WorkingDir + _T("\\ThinPack"), FALSE);
178 m_bPack = m_regThinPack;
179 this->m_regAutoLoad = CRegDWORD(CString(_T("Software\\TortoiseGit\\History\\PushDlgAutoLoad\\"))+WorkingDir,
180 m_bAutoLoad);
181 m_bAutoLoad = this->m_regAutoLoad;
182 if(!CAppUtils::IsSSHPutty())
183 m_bAutoLoad = false;
185 m_BrowseLocalRef.m_bRightArrow = TRUE;
186 m_BrowseLocalRef.m_bDefaultClick = FALSE;
187 m_BrowseLocalRef.m_bMarkDefault = 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 m_regRecurseSubmodules = CRegDWORD(
198 CString(_T("Software\\TortoiseGit\\History\\PushRecurseSubmodules\\")) + WorkingDir, m_RecurseSubmodules);
199 m_RecurseSubmodules = m_regRecurseSubmodules;
200 m_RecurseSubmodulesCombo.AddString(CString(MAKEINTRESOURCE(IDS_NONE)));
201 m_RecurseSubmodulesCombo.AddString(CString(MAKEINTRESOURCE(IDS_RECURSE_SUBMODULES_CHECK)));
202 m_RecurseSubmodulesCombo.AddString(CString(MAKEINTRESOURCE(IDS_RECURSE_SUBMODULES_ONDEMAND)));
203 m_RecurseSubmodulesCombo.SetCurSel(m_RecurseSubmodules);
205 if (CAppUtils::GetMsysgitVersion() < 0x01080500)
206 GetDlgItem(IDC_FORCE_WITH_LEASE)->EnableWindow(FALSE);
208 Refresh();
210 this->UpdateData(false);
212 OnBnClickedPushall();
213 return TRUE;
216 void CPushDlg::Refresh()
218 CString WorkingDir=g_Git.m_CurrentDir;
219 WorkingDir.Replace(_T(':'),_T('_'));
221 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
222 m_RemoteReg = remote;
223 int sel = -1;
225 STRING_VECTOR list;
226 m_Remote.Reset();
228 if(!g_Git.GetRemoteList(list))
230 if (list.size() > 1)
231 m_Remote.AddString(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)));
232 for (unsigned int i = 0; i < list.size(); ++i)
234 m_Remote.AddString(list[i]);
235 if(list[i] == remote)
236 sel = i + (list.size() > 1 ? 1 : 0);
239 else
240 MessageBox(g_Git.GetGitLastErr(_T("Could not get list of remotes.")), _T("TortoiseGit"), MB_ICONERROR);
241 // if the last selected remote was "- All -" and "- All -" is still in the list -> select it
242 if (list.size() > 1 && remote == CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES)))
243 sel = 0;
244 m_Remote.SetCurSel(sel);
246 int current = -1;
247 list.clear();
248 m_BranchSource.Reset();
249 m_BranchSource.SetMaxHistoryItems(0x7FFFFFFF);
250 if(!g_Git.GetBranchList(list,&current))
251 m_BranchSource.SetList(list);
252 else
253 MessageBox(g_Git.GetGitLastErr(_T("Could not get list of local branches.")), _T("TortoiseGit"), MB_ICONERROR);
254 if (wcsncmp(m_BranchSourceName, _T("refs/"), 5) == 0)
255 m_BranchSourceName = m_BranchSourceName.Mid(5);
256 if (wcsncmp(m_BranchSourceName, _T("heads/"), 6) == 0)
258 m_BranchSourceName = m_BranchSourceName.Mid(6);
259 m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
261 else if (wcsncmp(m_BranchSourceName, _T("remotes/"), 8) == 0)
262 m_BranchSource.SetCurSel(m_BranchSource.FindStringExact(-1, m_BranchSourceName));
263 else if (m_BranchSourceName.IsEmpty())
264 m_BranchSource.SetCurSel(current);
265 else
266 m_BranchSource.SetWindowText(m_BranchSourceName);
268 GetRemoteBranch(m_BranchSource.GetString());
270 this->GetDlgItem(IDOK)->EnableWindow(m_BranchSource.GetCount() != 0);
272 if (list.size() > 1 && m_bPushAllRemotes)
273 m_Remote.SetCurSel(0);
274 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
277 void CPushDlg::GetRemoteBranch(CString currentBranch)
279 CString WorkingDir=g_Git.m_CurrentDir;
280 WorkingDir.Replace(_T(':'), _T('_'));
282 if (currentBranch.IsEmpty())
284 EnDisablePushRemoteArchiveBranch();
285 return;
288 CString configName;
290 configName.Format(L"branch.%s.pushremote", currentBranch);
291 CString pushRemote = g_Git.GetConfigValue(configName);
292 if( pushRemote.IsEmpty() )
294 pushRemote = g_Git.GetConfigValue(L"remote.pushdefault");
295 if (pushRemote.IsEmpty())
297 configName.Format(L"branch.%s.remote", currentBranch);
298 pushRemote = g_Git.GetConfigValue(configName);
302 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir));
304 if (!pushRemote.IsEmpty())
306 remote = pushRemote;
307 // if a pushRemote exists, select it
308 for (int i = 0; i < m_Remote.GetCount(); ++i)
310 CString str;
311 int n = m_Remote.GetLBTextLen(i);
312 m_Remote.GetLBText(i, str.GetBuffer(n));
313 str.ReleaseBuffer();
314 if (str == pushRemote)
316 m_Remote.SetCurSel(i);
317 break;
321 // select the only remote if only one exists
322 else if (m_Remote.GetCount() == 1)
323 m_Remote.SetCurSel(0);
324 // select no remote if no push-remote is specified AND push to all remotes is not selected
325 else if (!(m_Remote.GetCount() > 1 && m_Remote.GetCurSel() == 0))
327 m_Remote.SetCurSel(-1);
330 //Select pull-branch from current branch
331 configName.Format(L"branch.%s.pushbranch", currentBranch);
332 CString pushBranch = g_Git.GetConfigValue(configName); // do not strip branch name (for gerrit), see issue #1609)
333 if( pushBranch.IsEmpty() )
335 configName.Format(L"branch.%s.merge", currentBranch);
336 pushBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
339 m_BranchRemote.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir, _T("branch"));
340 if( !pushBranch.IsEmpty() )
341 m_BranchRemote.AddString(pushBranch);
343 EnDisablePushRemoteArchiveBranch();
346 void CPushDlg::EnDisablePushRemoteArchiveBranch()
348 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())
350 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHBRANCH, FALSE);
351 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHREMOTE, FALSE);
352 bool enableUpstream = (GetCheckedRadioButton(IDC_RD_REMOTE, IDC_RD_URL) != IDC_RD_URL && (!m_BranchSource.GetString().Trim().IsEmpty() || m_bPushAllBranches));
353 DialogEnableWindow(IDC_PROC_PUSH_SET_UPSTREAM, enableUpstream);
354 if (m_bSetUpstream && !enableUpstream)
355 m_bSetUpstream = FALSE;
356 m_bSetPushRemote = FALSE;
357 m_bSetPushBranch = FALSE;
358 UpdateData(FALSE);
360 else
362 DialogEnableWindow(IDC_PROC_PUSH_SET_UPSTREAM, TRUE);
363 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHBRANCH, !m_bSetUpstream);
364 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHREMOTE, !m_bSetUpstream);
368 // CPushDlg message handlers
370 void CPushDlg::OnBnClickedRd()
372 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
374 m_Remote.EnableWindow(TRUE);
375 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(TRUE);
376 m_RemoteURL.EnableWindow(FALSE);
378 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
380 CString clippath = CAppUtils::GetClipboardLink();
381 if (clippath.IsEmpty())
382 m_RemoteURL.SetCurSel(0);
383 else
384 m_RemoteURL.SetWindowText(clippath);
385 m_Remote.EnableWindow(FALSE);
386 GetDlgItem(IDC_REMOTE_MANAGE)->EnableWindow(FALSE);
387 m_RemoteURL.EnableWindow(TRUE);
389 EnDisablePushRemoteArchiveBranch();
393 void CPushDlg::OnCbnSelchangeBranchSource()
395 GetRemoteBranch(m_BranchSource.GetString());
398 void CPushDlg::OnBnClickedOk()
400 CHorizontalResizableStandAloneDialog::UpdateData(TRUE);
402 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_REMOTE)
404 m_URL=m_Remote.GetString();
405 if (m_URL.IsEmpty())
407 CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_REMOTEEMPTY, IDS_APPNAME, MB_OK);
408 return;
410 m_bPushAllRemotes = (m_Remote.GetCurSel() == 0 && m_Remote.GetCount() > 1);
412 if( GetCheckedRadioButton(IDC_RD_REMOTE,IDC_RD_URL) == IDC_RD_URL)
414 m_URL=m_RemoteURL.GetString();
417 if (!m_bPushAllBranches)
419 this->m_BranchRemoteName=m_BranchRemote.GetString().Trim();
420 this->m_BranchSourceName=m_BranchSource.GetString().Trim();
422 if (m_BranchSourceName.IsEmpty() && m_BranchRemoteName.IsEmpty())
424 if (CMessageBox::Show(NULL, IDS_B_T_BOTHEMPTY, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO) != IDYES)
425 return;
427 if (m_BranchSourceName.IsEmpty() && !m_BranchRemoteName.IsEmpty())
429 if (CMessageBox::Show(NULL, IDS_B_T_LOCALEMPTY, IDS_APPNAME, MB_ICONEXCLAMATION | MB_YESNO) != IDYES)
430 return;
432 else if (!m_BranchRemoteName.IsEmpty() && !g_Git.IsBranchNameValid(this->m_BranchRemoteName))
434 CMessageBox::Show(NULL, IDS_B_T_INVALID, IDS_APPNAME, MB_OK);
435 return;
437 else if (!m_BranchSourceName.IsEmpty() && !g_Git.IsBranchTagNameUnique(m_BranchSourceName))
439 CMessageBox::Show(NULL, IDS_B_T_NOT_UNIQUE, IDS_APPNAME, MB_OK | MB_ICONEXCLAMATION);
440 return;
442 else
444 // do not store branch names on removal
445 if (m_RemoteURL.IsWindowEnabled())
446 m_RemoteURL.SaveHistory(); // do not store Remote URLs if not used
447 this->m_BranchRemote.SaveHistory();
448 m_RemoteReg = m_Remote.GetString();
450 if (!m_BranchSourceName.IsEmpty())
452 CString configName;
453 if (m_bSetPushBranch)
455 configName.Format(L"branch.%s.pushbranch", m_BranchSourceName);
456 if (!m_BranchRemoteName.IsEmpty())
457 g_Git.SetConfigValue(configName, m_BranchRemoteName);
458 else
459 g_Git.UnsetConfigValue(configName);
461 if (m_bSetPushRemote)
463 configName.Format(L"branch.%s.pushremote", m_BranchSourceName);
464 if (!m_URL.IsEmpty())
465 g_Git.SetConfigValue(configName, m_URL);
466 else
467 g_Git.UnsetConfigValue(configName);
473 m_regPushAllBranches = m_bPushAllBranches;
474 m_regPushAllRemotes = m_bPushAllRemotes;
475 m_regThinPack = m_bPack;
476 this->m_regAutoLoad = m_bAutoLoad ;
477 m_RecurseSubmodules = m_RecurseSubmodulesCombo.GetCurSel();
478 if (m_RecurseSubmodules == 2 && CAppUtils::GetMsysgitVersion() < 0x01070b00)
480 CString gitver;
481 gitver.Format(IDS_GITVER_REQUIRED, _T("--recurse-submodules=on-demand"), _T("1.7.11"));
482 CMessageBox::Show(m_hWnd, gitver, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
483 return;
485 m_regRecurseSubmodules = m_RecurseSubmodules;
487 CHorizontalResizableStandAloneDialog::OnOK();
490 void CPushDlg::OnBnClickedRemoteManage()
492 CAppUtils::LaunchRemoteSetting();
493 Refresh();
496 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
498 switch (m_BrowseLocalRef.GetCurrentEntry())
500 case 0: /* Browse Refence*/
502 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource, gPickRef_Head))
503 OnCbnSelchangeBranchSource();
505 break;
507 case 1: /* Log */
509 CLogDlg dlg;
510 CString revision;
511 m_BranchSource.GetWindowText(revision);
512 dlg.SetParams(CTGitPath(), CTGitPath(), revision, revision, 0);
513 dlg.SetSelect(true);
514 if(dlg.DoModal() == IDOK)
516 if (dlg.GetSelectedHash().IsEmpty())
517 return;
519 m_BranchSource.SetWindowText(dlg.GetSelectedHash());
520 OnCbnSelchangeBranchSource();
523 break;
525 case 2: /*RefLog*/
527 CRefLogDlg dlg;
528 if(dlg.DoModal() == IDOK)
530 m_BranchSource.SetWindowText(dlg.m_SelectedHash);
531 OnCbnSelchangeBranchSource();
534 break;
538 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
540 CString remoteBranchName;
541 CString remoteName;
542 m_BranchRemote.GetWindowText(remoteBranchName);
543 remoteName = m_Remote.GetString();
544 remoteBranchName = remoteName + '/' + remoteBranchName;
545 remoteBranchName = CBrowseRefsDlg::PickRef(false, remoteBranchName, gPickRef_Remote);
546 if(remoteBranchName.IsEmpty())
547 return; //Canceled
548 remoteBranchName = remoteBranchName.Mid(13);//Strip 'refs/remotes/'
549 int slashPlace = remoteBranchName.Find('/');
550 remoteName = remoteBranchName.Left(slashPlace);
551 remoteBranchName = remoteBranchName.Mid(slashPlace + 1); //Strip remote name (for example 'origin/')
553 //Select remote
554 int remoteSel = m_Remote.FindStringExact(0,remoteName);
555 if(remoteSel >= 0)
556 m_Remote.SetCurSel(remoteSel);
558 //Select branch
559 m_BranchRemote.AddString(remoteBranchName, 0);
562 BOOL CPushDlg::PreTranslateMessage(MSG* pMsg)
564 if (pMsg->message == WM_KEYDOWN)
566 switch (pMsg->wParam)
568 case VK_F5:
570 Refresh();
572 break;
576 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg);
579 void CPushDlg::OnBnClickedPushall()
581 this->UpdateData();
582 this->GetDlgItem(IDC_BRANCH_REMOTE)->EnableWindow(!m_bPushAllBranches);
583 this->GetDlgItem(IDC_BRANCH_SOURCE)->EnableWindow(!m_bPushAllBranches);
584 this->GetDlgItem(IDC_BUTTON_BROWSE_SOURCE_BRANCH)->EnableWindow(!m_bPushAllBranches);
585 this->GetDlgItem(IDC_BUTTON_BROWSE_DEST_BRANCH)->EnableWindow(!m_bPushAllBranches);
586 EnDisablePushRemoteArchiveBranch();
589 void CPushDlg::OnBnClickedForce()
591 UpdateData();
592 if (CAppUtils::GetMsysgitVersion() >= 0x01080500)
593 GetDlgItem(IDC_FORCE_WITH_LEASE)->EnableWindow(m_bTags || m_bForce ? FALSE : TRUE);
596 void CPushDlg::OnBnClickedForceWithLease()
598 UpdateData();
599 GetDlgItem(IDC_FORCE)->EnableWindow(m_bForceWithLease ? FALSE : TRUE);
600 GetDlgItem(IDC_TAGS)->EnableWindow(m_bForceWithLease ? FALSE : TRUE);
603 void CPushDlg::OnBnClickedTags()
605 UpdateData();
606 if (CAppUtils::GetMsysgitVersion() >= 0x01080500)
607 GetDlgItem(IDC_FORCE_WITH_LEASE)->EnableWindow(m_bTags || m_bForce ? FALSE : TRUE);
610 void CPushDlg::OnBnClickedProcPushSetUpstream()
612 UpdateData();
613 this->GetDlgItem(IDC_PROC_PUSH_SET_PUSHREMOTE)->EnableWindow(!m_bSetUpstream);
614 this->GetDlgItem(IDC_PROC_PUSH_SET_PUSHBRANCH)->EnableWindow(!m_bSetUpstream);
615 m_bSetPushBranch = FALSE;
616 m_bSetPushRemote = FALSE;
617 UpdateData(FALSE);
620 void CPushDlg::OnBnClickedProcPushSetPushremote()
622 UpdateData();
623 this->GetDlgItem(IDC_PROC_PUSH_SET_UPSTREAM)->EnableWindow(!(m_bSetPushBranch || m_bSetPushRemote));
624 m_bSetUpstream = FALSE;
625 UpdateData(FALSE);