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 // PushDlg.cpp : implementation file
24 #include "TortoiseProc.h"
31 #include "BrowseRefsDlg.h"
32 #include "RefLogDlg.h"
33 #include "MessageBox.h"
37 IMPLEMENT_DYNAMIC(CPushDlg
, CHorizontalResizableStandAloneDialog
)
39 CPushDlg::CPushDlg(CWnd
* pParent
/*=NULL*/)
40 : CHorizontalResizableStandAloneDialog(CPushDlg::IDD
, pParent
)
41 , m_bPushAllBranches(FALSE
)
46 , m_bPushAllRemotes(FALSE
)
47 , m_bSetPushBranch(FALSE
)
48 , m_bSetPushRemote(FALSE
)
49 , m_bSetUpstream(FALSE
)
51 m_bAutoLoad
= CAppUtils::IsSSHPutty();
58 void CPushDlg::DoDataExchange(CDataExchange
* pDX
)
60 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX
);
61 DDX_Control(pDX
, IDC_BRANCH_REMOTE
, this->m_BranchRemote
);
62 DDX_Control(pDX
, IDC_BRANCH_SOURCE
, this->m_BranchSource
);
63 DDX_Control(pDX
, IDC_REMOTE
, this->m_Remote
);
64 DDX_Control(pDX
, IDC_URL
, this->m_RemoteURL
);
65 DDX_Control(pDX
, IDC_BUTTON_BROWSE_SOURCE_BRANCH
, m_BrowseLocalRef
);
66 DDX_Check(pDX
,IDC_FORCE
,this->m_bForce
);
67 DDX_Check(pDX
,IDC_PUSHALL
,this->m_bPushAllBranches
);
68 DDX_Check(pDX
,IDC_PACK
,this->m_bPack
);
69 DDX_Check(pDX
,IDC_TAGS
,this->m_bTags
);
70 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
,this->m_bAutoLoad
);
71 DDX_Check(pDX
, IDC_PROC_PUSH_SET_PUSHREMOTE
, m_bSetPushRemote
);
72 DDX_Check(pDX
, IDC_PROC_PUSH_SET_PUSHBRANCH
, m_bSetPushBranch
);
73 DDX_Check(pDX
, IDC_PROC_PUSH_SET_UPSTREAM
, m_bSetUpstream
);
76 BEGIN_MESSAGE_MAP(CPushDlg
, CHorizontalResizableStandAloneDialog
)
77 ON_BN_CLICKED(IDC_RD_REMOTE
, &CPushDlg::OnBnClickedRd
)
78 ON_BN_CLICKED(IDC_RD_URL
, &CPushDlg::OnBnClickedRd
)
79 ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE
, &CPushDlg::OnCbnSelchangeBranchSource
)
80 ON_CBN_SELCHANGE(IDC_REMOTE
, &CPushDlg::EnDisablePushRemoteArchiveBranch
)
81 ON_BN_CLICKED(IDOK
, &CPushDlg::OnBnClickedOk
)
82 ON_BN_CLICKED(IDC_REMOTE_MANAGE
, &CPushDlg::OnBnClickedRemoteManage
)
83 ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH
, &CPushDlg::OnBnClickedButtonBrowseSourceBranch
)
84 ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH
, &CPushDlg::OnBnClickedButtonBrowseDestBranch
)
85 ON_BN_CLICKED(IDC_PUSHALL
, &CPushDlg::OnBnClickedPushall
)
86 ON_BN_CLICKED(IDC_PROC_PUSH_SET_UPSTREAM
, &CPushDlg::OnBnClickedProcPushSetUpstream
)
87 ON_BN_CLICKED(IDC_PROC_PUSH_SET_PUSHREMOTE
, &CPushDlg::OnBnClickedProcPushSetPushremote
)
88 ON_BN_CLICKED(IDC_PROC_PUSH_SET_PUSHBRANCH
, &CPushDlg::OnBnClickedProcPushSetPushremote
)
91 BOOL
CPushDlg::OnInitDialog()
93 CHorizontalResizableStandAloneDialog::OnInitDialog();
94 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
96 AddAnchor(IDOK
,BOTTOM_RIGHT
);
97 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
98 AddAnchor(IDC_BRANCH_GROUP
, TOP_LEFT
,TOP_RIGHT
);
99 AddAnchor(IDC_STATIC_REMOTE
, TOP_LEFT
);
100 AddAnchor(IDC_STATIC_SOURCE
, TOP_LEFT
);
102 AddAnchor(IDC_PUSHALL
, TOP_LEFT
);
103 AddAnchor(IDC_BRANCH_REMOTE
, TOP_LEFT
, TOP_RIGHT
);
104 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH
, TOP_RIGHT
);
105 AddAnchor(IDC_BRANCH_SOURCE
, TOP_LEFT
, TOP_RIGHT
);
106 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH
, TOP_RIGHT
);
108 AddAnchor(IDC_URL_GROUP
, TOP_LEFT
,TOP_RIGHT
);
109 AddAnchor(IDC_RD_REMOTE
, TOP_LEFT
);
110 AddAnchor(IDC_RD_URL
, TOP_LEFT
);
112 AddAnchor(IDC_REMOTE
, TOP_LEFT
, TOP_RIGHT
);
114 AddAnchor(IDC_URL
, TOP_LEFT
,TOP_RIGHT
);
116 AddAnchor(IDC_OPTION_GROUP
, TOP_LEFT
,TOP_RIGHT
);
118 AddAnchor(IDC_FORCE
, TOP_LEFT
);
119 AddAnchor(IDC_PACK
, TOP_LEFT
);
120 AddAnchor(IDC_TAGS
, TOP_LEFT
);
121 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,TOP_LEFT
);
122 AddAnchor(IDC_PROC_PUSH_SET_PUSHBRANCH
, TOP_LEFT
);
123 AddAnchor(IDC_PROC_PUSH_SET_PUSHREMOTE
, TOP_LEFT
);
124 AddAnchor(IDC_PROC_PUSH_SET_UPSTREAM
, TOP_LEFT
);
126 AddAnchor(IDC_REMOTE_MANAGE
,TOP_RIGHT
);
127 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
131 AdjustControlSize(IDC_RD_REMOTE
);
132 AdjustControlSize(IDC_RD_URL
);
133 AdjustControlSize(IDC_PUSHALL
);
134 AdjustControlSize(IDC_FORCE
);
135 AdjustControlSize(IDC_PACK
);
136 AdjustControlSize(IDC_TAGS
);
137 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD
);
138 AdjustControlSize(IDC_PROC_PUSH_SET_PUSHBRANCH
);
139 AdjustControlSize(IDC_PROC_PUSH_SET_PUSHREMOTE
);
140 AdjustControlSize(IDC_PROC_PUSH_SET_UPSTREAM
);
142 CString sWindowTitle
;
143 GetWindowText(sWindowTitle
);
144 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
146 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow(CAppUtils::IsSSHPutty());
148 EnableSaveRestore(_T("PushDlg"));
150 m_RemoteURL
.SetURLHistory(TRUE
);
152 CString WorkingDir
=g_Git
.m_CurrentDir
;
153 WorkingDir
.Replace(_T(':'),_T('_'));
154 m_RemoteURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir
, _T("url"));
155 CString clippath
=CAppUtils::GetClipboardLink();
156 if(clippath
.IsEmpty())
157 m_RemoteURL
.SetCurSel(0);
159 m_RemoteURL
.SetWindowText(clippath
);
161 m_RemoteURL
.EnableWindow(FALSE
);
162 CheckRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
,IDC_RD_REMOTE
);
165 this->m_regAutoLoad
= CRegDWORD(CString(_T("Software\\TortoiseGit\\History\\PushDlgAutoLoad\\"))+WorkingDir
,
167 m_bAutoLoad
= this->m_regAutoLoad
;
168 if(!CAppUtils::IsSSHPutty())
171 m_BrowseLocalRef
.m_bRightArrow
= TRUE
;
172 m_BrowseLocalRef
.m_bDefaultClick
= FALSE
;
173 m_BrowseLocalRef
.m_bMarkDefault
= FALSE
;
174 m_BrowseLocalRef
.AddEntry(CString(MAKEINTRESOURCE(IDS_REFBROWSE
)));
175 m_BrowseLocalRef
.AddEntry(CString(MAKEINTRESOURCE(IDS_LOG
)));
176 m_BrowseLocalRef
.AddEntry(CString(MAKEINTRESOURCE(IDS_REFLOG
)));
178 m_tooltips
.Create(this);
179 m_tooltips
.AddTool(IDC_PROC_PUSH_SET_PUSHBRANCH
, IDS_PUSHDLG_PUSHBRANCH_TT
);
180 m_tooltips
.AddTool(IDC_PROC_PUSH_SET_PUSHREMOTE
, IDS_PUSHDLG_PUSHREMOTE_TT
);
184 this->UpdateData(false);
188 void CPushDlg::Refresh()
190 CString WorkingDir
=g_Git
.m_CurrentDir
;
191 WorkingDir
.Replace(_T(':'),_T('_'));
193 CRegString
remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir
));
194 m_RemoteReg
= remote
;
200 list
.push_back(CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES
)));
201 if(!g_Git
.GetRemoteList(list
))
203 if (list
.size() <= 2)
204 list
.erase(list
.begin());
206 for(unsigned int i
=0;i
<list
.size();i
++)
208 m_Remote
.AddString(list
[i
]);
209 if(list
[i
] == remote
)
213 // if the last selected remote was "- All -" and "- All -" is still in the list -> select it
214 if (list
.size() > 1 && remote
== CString(MAKEINTRESOURCE(IDS_PROC_PUSHFETCH_ALLREMOTES
)))
216 m_Remote
.SetCurSel(sel
);
220 m_BranchSource
.Reset();
221 m_BranchSource
.AddString(_T(" ")); // empty string does not work, for removal of remote branches/tags
222 m_BranchSource
.SetMaxHistoryItems(0x7FFFFFFF);
223 if(!g_Git
.GetBranchList(list
,¤t
))
225 for(unsigned int i
=0;i
<list
.size();i
++)
226 m_BranchSource
.AddString(list
[i
]);
227 current
++; // shift for " "
229 if (wcsncmp(m_BranchSourceName
, _T("refs/"), 5) == 0)
230 m_BranchSourceName
= m_BranchSourceName
.Mid(5);
231 if (wcsncmp(m_BranchSourceName
, _T("heads/"), 6) == 0)
233 m_BranchSourceName
= m_BranchSourceName
.Mid(6);
234 m_BranchSource
.SetCurSel(m_BranchSource
.FindStringExact(-1, m_BranchSourceName
));
236 else if (wcsncmp(m_BranchSourceName
, _T("remotes/"), 8) == 0)
237 m_BranchSource
.SetCurSel(m_BranchSource
.FindStringExact(-1, m_BranchSourceName
));
239 m_BranchSource
.SetCurSel(current
);
241 GetRemoteBranch(m_BranchSource
.GetString());
243 this->GetDlgItem(IDOK
)->EnableWindow(m_BranchSource
.GetCount() != 0);
246 void CPushDlg::GetRemoteBranch(CString currentBranch
)
248 CString WorkingDir
=g_Git
.m_CurrentDir
;
249 WorkingDir
.Replace(_T(':'), _T('_'));
251 if (currentBranch
.IsEmpty())
253 EnDisablePushRemoteArchiveBranch();
259 configName
.Format(L
"branch.%s.pushremote", currentBranch
);
260 CString pushRemote
= g_Git
.GetConfigValue(configName
);
261 if( pushRemote
.IsEmpty() )
263 configName
.Format(L
"branch.%s.remote", currentBranch
);
264 pushRemote
= g_Git
.GetConfigValue(configName
);
267 CRegString
remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir
));
269 if (!pushRemote
.IsEmpty())
272 // if a pushRemote exists, select it
273 for (int i
= 0; i
< m_Remote
.GetCount(); i
++)
276 int n
= m_Remote
.GetLBTextLen(i
);
277 m_Remote
.GetLBText(i
, str
.GetBuffer(n
));
279 if (str
== pushRemote
)
281 m_Remote
.SetCurSel(i
);
286 // select no remote if no push-remote is specified AND push to all remotes is not selected
287 else if (!(m_Remote
.GetCount() > 1 && m_Remote
.GetCurSel() == 0))
289 m_Remote
.SetCurSel(-1);
292 //Select pull-branch from current branch
293 configName
.Format(L
"branch.%s.pushbranch", currentBranch
);
294 CString pushBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
295 if( pushBranch
.IsEmpty() )
297 configName
.Format(L
"branch.%s.merge", currentBranch
);
298 pushBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
301 m_BranchRemote
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir
, _T("branch"));
302 if( !pushBranch
.IsEmpty() )
303 m_BranchRemote
.AddString(pushBranch
);
305 EnDisablePushRemoteArchiveBranch();
308 void CPushDlg::EnDisablePushRemoteArchiveBranch()
310 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())
312 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHBRANCH
, FALSE
);
313 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHREMOTE
, FALSE
);
314 bool enableUpstream
= (GetCheckedRadioButton(IDC_RD_REMOTE
, IDC_RD_URL
) != IDC_RD_URL
&& (!m_BranchSource
.GetString().Trim().IsEmpty() || m_bPushAllBranches
));
315 DialogEnableWindow(IDC_PROC_PUSH_SET_UPSTREAM
, enableUpstream
);
316 if (m_bSetUpstream
&& !enableUpstream
)
317 m_bSetUpstream
= FALSE
;
318 m_bSetPushRemote
= FALSE
;
319 m_bSetPushBranch
= FALSE
;
324 DialogEnableWindow(IDC_PROC_PUSH_SET_UPSTREAM
, TRUE
);
325 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHBRANCH
, !m_bSetUpstream
);
326 DialogEnableWindow(IDC_PROC_PUSH_SET_PUSHREMOTE
, !m_bSetUpstream
);
330 // CPushDlg message handlers
332 void CPushDlg::OnBnClickedRd()
334 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_REMOTE
)
336 m_Remote
.EnableWindow(TRUE
);
337 GetDlgItem(IDC_REMOTE_MANAGE
)->EnableWindow(TRUE
);
338 m_RemoteURL
.EnableWindow(FALSE
);
340 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_URL
)
342 m_Remote
.EnableWindow(FALSE
);
343 GetDlgItem(IDC_REMOTE_MANAGE
)->EnableWindow(FALSE
);
344 m_RemoteURL
.EnableWindow(TRUE
);
346 EnDisablePushRemoteArchiveBranch();
350 void CPushDlg::OnCbnSelchangeBranchSource()
352 GetRemoteBranch(m_BranchSource
.GetString());
355 void CPushDlg::OnBnClickedOk()
357 CHorizontalResizableStandAloneDialog::UpdateData(TRUE
);
359 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_REMOTE
)
361 m_URL
=m_Remote
.GetString();
364 CMessageBox::Show(NULL
, IDS_PROC_GITCONFIG_REMOTEEMPTY
, IDS_APPNAME
, MB_OK
);
367 m_bPushAllRemotes
= (m_Remote
.GetCurSel() == 0 && m_Remote
.GetCount() > 1);
369 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_URL
)
371 m_URL
=m_RemoteURL
.GetString();
374 if (!m_bPushAllBranches
)
376 this->m_BranchRemoteName
=m_BranchRemote
.GetString().Trim();
377 this->m_BranchSourceName
=m_BranchSource
.GetString().Trim();
379 if (m_BranchSourceName
.IsEmpty() && m_BranchRemoteName
.IsEmpty())
381 if (CMessageBox::Show(NULL
, IDS_B_T_BOTHEMPTY
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
) == IDNO
)
384 if (m_BranchSourceName
.IsEmpty() && !m_BranchRemoteName
.IsEmpty())
386 if (CMessageBox::Show(NULL
, IDS_B_T_LOCALEMPTY
, IDS_APPNAME
, MB_ICONEXCLAMATION
| MB_YESNO
) == IDNO
)
389 else if (!m_BranchRemoteName
.IsEmpty() && !g_Git
.IsBranchNameValid(this->m_BranchRemoteName
))
391 CMessageBox::Show(NULL
, IDS_B_T_INVALID
, IDS_APPNAME
, MB_OK
);
394 else if (!m_BranchSourceName
.IsEmpty() && !g_Git
.IsBranchTagNameUnique(m_BranchSourceName
))
396 CMessageBox::Show(NULL
, IDS_B_T_NOT_UNIQUE
, IDS_APPNAME
, MB_OK
| MB_ICONEXCLAMATION
);
401 // do not store branch names on removal
402 this->m_RemoteURL
.SaveHistory();
403 this->m_BranchRemote
.SaveHistory();
404 m_RemoteReg
= m_Remote
.GetString();
406 if (!m_BranchSourceName
.IsEmpty())
409 if (m_bSetPushBranch
)
411 configName
.Format(L
"branch.%s.pushbranch", m_BranchSourceName
);
412 if (!m_BranchRemoteName
.IsEmpty())
413 g_Git
.SetConfigValue(configName
, m_BranchRemoteName
);
415 g_Git
.UnsetConfigValue(configName
);
417 if (m_bSetPushRemote
)
419 configName
.Format(L
"branch.%s.pushremote", m_BranchSourceName
);
420 if (!m_URL
.IsEmpty())
421 g_Git
.SetConfigValue(configName
, m_URL
);
423 g_Git
.UnsetConfigValue(configName
);
429 this->m_regAutoLoad
= m_bAutoLoad
;
431 CHorizontalResizableStandAloneDialog::OnOK();
434 void CPushDlg::OnBnClickedRemoteManage()
436 CAppUtils::LaunchRemoteSetting();
440 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
442 switch (m_BrowseLocalRef
.GetCurrentEntry())
444 case 0: /* Browse Refence*/
446 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource
, gPickRef_Head
))
447 OnCbnSelchangeBranchSource();
455 if(dlg
.DoModal() == IDOK
)
457 if (dlg
.GetSelectedHash().IsEmpty())
460 m_BranchSource
.SetWindowText(dlg
.GetSelectedHash());
461 OnCbnSelchangeBranchSource();
469 if(dlg
.DoModal() == IDOK
)
471 m_BranchSource
.SetWindowText(dlg
.m_SelectedHash
);
472 OnCbnSelchangeBranchSource();
479 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
481 CString remoteBranchName
;
483 m_BranchRemote
.GetWindowText(remoteBranchName
);
484 remoteName
= m_Remote
.GetString();
485 remoteBranchName
= remoteName
+ '/' + remoteBranchName
;
486 remoteBranchName
= CBrowseRefsDlg::PickRef(false, remoteBranchName
, gPickRef_Remote
);
487 if(remoteBranchName
.IsEmpty())
489 remoteBranchName
= remoteBranchName
.Mid(13);//Strip 'refs/remotes/'
490 int slashPlace
= remoteBranchName
.Find('/');
491 remoteName
= remoteBranchName
.Left(slashPlace
);
492 remoteBranchName
= remoteBranchName
.Mid(slashPlace
+ 1); //Strip remote name (for example 'origin/')
495 int remoteSel
= m_Remote
.FindStringExact(0,remoteName
);
497 m_Remote
.SetCurSel(remoteSel
);
500 m_BranchRemote
.AddString(remoteBranchName
);
503 BOOL
CPushDlg::PreTranslateMessage(MSG
* pMsg
)
505 m_tooltips
.RelayEvent(pMsg
);
507 if (pMsg
->message
== WM_KEYDOWN
)
509 switch (pMsg
->wParam
)
519 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg
);
522 void CPushDlg::OnBnClickedPushall()
525 this->GetDlgItem(IDC_BRANCH_REMOTE
)->EnableWindow(!m_bPushAllBranches
);
526 this->GetDlgItem(IDC_BRANCH_SOURCE
)->EnableWindow(!m_bPushAllBranches
);
527 this->GetDlgItem(IDC_BUTTON_BROWSE_SOURCE_BRANCH
)->EnableWindow(!m_bPushAllBranches
);
528 this->GetDlgItem(IDC_BUTTON_BROWSE_DEST_BRANCH
)->EnableWindow(!m_bPushAllBranches
);
529 this->GetDlgItem(IDC_TAGS
)->EnableWindow(!m_bPushAllBranches
);
530 if (m_bTags
&& m_bPushAllBranches
)
535 EnDisablePushRemoteArchiveBranch();
538 void CPushDlg::OnBnClickedProcPushSetUpstream()
541 this->GetDlgItem(IDC_PROC_PUSH_SET_PUSHREMOTE
)->EnableWindow(!m_bSetUpstream
);
542 this->GetDlgItem(IDC_PROC_PUSH_SET_PUSHBRANCH
)->EnableWindow(!m_bSetUpstream
);
543 m_bSetPushBranch
= FALSE
;
544 m_bSetPushRemote
= FALSE
;
548 void CPushDlg::OnBnClickedProcPushSetPushremote()
551 this->GetDlgItem(IDC_PROC_PUSH_SET_UPSTREAM
)->EnableWindow(!(m_bSetPushBranch
|| m_bSetPushRemote
));
552 m_bSetUpstream
= FALSE
;