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
)
47 m_bAutoLoad
= CAppUtils::IsSSHPutty();
54 void CPushDlg::DoDataExchange(CDataExchange
* pDX
)
56 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX
);
57 DDX_Control(pDX
, IDC_BRANCH_REMOTE
, this->m_BranchRemote
);
58 DDX_Control(pDX
, IDC_BRANCH_SOURCE
, this->m_BranchSource
);
59 DDX_Control(pDX
, IDC_REMOTE
, this->m_Remote
);
60 DDX_Control(pDX
, IDC_URL
, this->m_RemoteURL
);
61 DDX_Control(pDX
, IDC_BUTTON_BROWSE_SOURCE_BRANCH
, m_BrowseLocalRef
);
62 DDX_Check(pDX
,IDC_FORCE
,this->m_bForce
);
63 DDX_Check(pDX
,IDC_PUSHALL
,this->m_bPushAllBranches
);
64 DDX_Check(pDX
,IDC_PACK
,this->m_bPack
);
65 DDX_Check(pDX
,IDC_TAGS
,this->m_bTags
);
66 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
,this->m_bAutoLoad
);
69 BEGIN_MESSAGE_MAP(CPushDlg
, CHorizontalResizableStandAloneDialog
)
70 ON_BN_CLICKED(IDC_RD_REMOTE
, &CPushDlg::OnBnClickedRd
)
71 ON_BN_CLICKED(IDC_RD_URL
, &CPushDlg::OnBnClickedRd
)
72 ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE
, &CPushDlg::OnCbnSelchangeBranchSource
)
73 ON_BN_CLICKED(IDOK
, &CPushDlg::OnBnClickedOk
)
74 ON_BN_CLICKED(IDC_REMOTE_MANAGE
, &CPushDlg::OnBnClickedRemoteManage
)
75 ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH
, &CPushDlg::OnBnClickedButtonBrowseSourceBranch
)
76 ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH
, &CPushDlg::OnBnClickedButtonBrowseDestBranch
)
77 ON_BN_CLICKED(IDC_PUSHALL
, &CPushDlg::OnBnClickedPushall
)
80 BOOL
CPushDlg::OnInitDialog()
82 CHorizontalResizableStandAloneDialog::OnInitDialog();
83 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
85 AddAnchor(IDOK
,BOTTOM_RIGHT
);
86 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
87 AddAnchor(IDC_BRANCH_GROUP
, TOP_LEFT
,TOP_RIGHT
);
88 AddAnchor(IDC_STATIC_REMOTE
, TOP_LEFT
);
89 AddAnchor(IDC_STATIC_SOURCE
, TOP_LEFT
);
91 AddAnchor(IDC_PUSHALL
, TOP_LEFT
);
92 AddAnchor(IDC_BRANCH_REMOTE
, TOP_LEFT
, TOP_RIGHT
);
93 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH
, TOP_RIGHT
);
94 AddAnchor(IDC_BRANCH_SOURCE
, TOP_LEFT
, TOP_RIGHT
);
95 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH
, TOP_RIGHT
);
97 AddAnchor(IDC_URL_GROUP
, TOP_LEFT
,TOP_RIGHT
);
98 AddAnchor(IDC_RD_REMOTE
, TOP_LEFT
);
99 AddAnchor(IDC_RD_URL
, TOP_LEFT
);
101 AddAnchor(IDC_REMOTE
, TOP_LEFT
, TOP_RIGHT
);
103 AddAnchor(IDC_URL
, TOP_LEFT
,TOP_RIGHT
);
105 AddAnchor(IDC_OPTION_GROUP
, TOP_LEFT
,TOP_RIGHT
);
107 AddAnchor(IDC_FORCE
, TOP_LEFT
);
108 AddAnchor(IDC_PACK
, TOP_LEFT
);
109 AddAnchor(IDC_TAGS
, TOP_LEFT
);
110 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,TOP_LEFT
);
112 AddAnchor(IDC_REMOTE_MANAGE
,TOP_RIGHT
);
113 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
117 AdjustControlSize(IDC_RD_REMOTE
);
118 AdjustControlSize(IDC_RD_URL
);
119 AdjustControlSize(IDC_PUSHALL
);
120 AdjustControlSize(IDC_FORCE
);
121 AdjustControlSize(IDC_PACK
);
122 AdjustControlSize(IDC_TAGS
);
123 AdjustControlSize(IDC_PUTTYKEY_AUTOLOAD
);
125 CString sWindowTitle
;
126 GetWindowText(sWindowTitle
);
127 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
129 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow(CAppUtils::IsSSHPutty());
131 EnableSaveRestore(_T("PushDlg"));
133 m_RemoteURL
.SetURLHistory(TRUE
);
135 CString WorkingDir
=g_Git
.m_CurrentDir
;
136 WorkingDir
.Replace(_T(':'),_T('_'));
137 m_RemoteURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir
, _T("url"));
138 CString clippath
=CAppUtils::GetClipboardLink();
139 if(clippath
.IsEmpty())
140 m_RemoteURL
.SetCurSel(0);
142 m_RemoteURL
.SetWindowText(clippath
);
144 m_RemoteURL
.EnableWindow(FALSE
);
145 CheckRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
,IDC_RD_REMOTE
);
148 this->m_regAutoLoad
= CRegDWORD(CString(_T("Software\\TortoiseGit\\History\\PushDlgAutoLoad\\"))+WorkingDir
,
150 m_bAutoLoad
= this->m_regAutoLoad
;
151 if(!CAppUtils::IsSSHPutty())
154 m_BrowseLocalRef
.m_bRightArrow
= TRUE
;
155 m_BrowseLocalRef
.m_bDefaultClick
= FALSE
;
156 m_BrowseLocalRef
.m_bMarkDefault
= FALSE
;
157 m_BrowseLocalRef
.AddEntry(CString(MAKEINTRESOURCE(IDS_REFBROWSE
)));
158 m_BrowseLocalRef
.AddEntry(CString(MAKEINTRESOURCE(IDS_LOG
)));
159 m_BrowseLocalRef
.AddEntry(CString(MAKEINTRESOURCE(IDS_REFLOG
)));
164 //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());
166 this->UpdateData(false);
170 void CPushDlg::Refresh()
172 CString WorkingDir
=g_Git
.m_CurrentDir
;
173 WorkingDir
.Replace(_T(':'),_T('_'));
175 CRegString
remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir
));
176 m_RemoteReg
= remote
;
182 if(!g_Git
.GetRemoteList(list
))
184 for(unsigned int i
=0;i
<list
.size();i
++)
186 m_Remote
.AddString(list
[i
]);
187 if(list
[i
] == remote
)
191 m_Remote
.SetCurSel(sel
);
195 m_BranchSource
.Reset();
196 m_BranchSource
.AddString(_T(" ")); // empty string does not work, for removal of remote branches/tags
197 m_BranchSource
.SetMaxHistoryItems(0x7FFFFFFF);
198 if(!g_Git
.GetBranchList(list
,¤t
))
200 for(unsigned int i
=0;i
<list
.size();i
++)
201 m_BranchSource
.AddString(list
[i
]);
202 current
++; // shift for " "
204 if (wcsncmp(m_BranchSourceName
, _T("refs/"), 5) == 0)
205 m_BranchSourceName
= m_BranchSourceName
.Mid(5);
206 if (wcsncmp(m_BranchSourceName
, _T("heads/"), 6) == 0)
208 m_BranchSourceName
= m_BranchSourceName
.Mid(6);
209 m_BranchSource
.SetCurSel(m_BranchSource
.FindStringExact(-1, m_BranchSourceName
));
211 else if (wcsncmp(m_BranchSourceName
, _T("remotes/"), 8) == 0)
212 m_BranchSource
.SetCurSel(m_BranchSource
.FindStringExact(-1, m_BranchSourceName
));
214 m_BranchSource
.SetCurSel(current
);
216 GetRemoteBranch(m_BranchSource
.GetString());
218 this->GetDlgItem(IDOK
)->EnableWindow(m_BranchSource
.GetCount() != 0);
221 void CPushDlg::GetRemoteBranch(CString currentBranch
)
223 CString WorkingDir
=g_Git
.m_CurrentDir
;
224 WorkingDir
.Replace(_T(':'), _T('_'));
226 if (currentBranch
.IsEmpty())
231 configName
.Format(L
"branch.%s.pushremote", currentBranch
);
232 CString pushRemote
= g_Git
.GetConfigValue(configName
);
233 if( pushRemote
.IsEmpty() )
235 configName
.Format(L
"branch.%s.remote", currentBranch
);
236 pushRemote
= g_Git
.GetConfigValue(configName
);
239 CRegString
remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir
));
241 if( !pushRemote
.IsEmpty() )
244 //Select pull-branch from current branch
245 configName
.Format(L
"branch.%s.pushbranch", currentBranch
);
246 CString pushBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
247 if( pushBranch
.IsEmpty() )
249 configName
.Format(L
"branch.%s.merge", currentBranch
);
250 pushBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
253 m_BranchRemote
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir
, _T("branch"));
254 if( !pushBranch
.IsEmpty() )
255 m_BranchRemote
.AddString(pushBranch
);
258 // CPushDlg message handlers
260 void CPushDlg::OnBnClickedRd()
262 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_REMOTE
)
264 m_Remote
.EnableWindow(TRUE
);
265 GetDlgItem(IDC_REMOTE_MANAGE
)->EnableWindow(TRUE
);
266 m_RemoteURL
.EnableWindow(FALSE
);
268 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_URL
)
270 m_Remote
.EnableWindow(FALSE
);
271 GetDlgItem(IDC_REMOTE_MANAGE
)->EnableWindow(FALSE
);
272 m_RemoteURL
.EnableWindow(TRUE
);
277 void CPushDlg::OnCbnSelchangeBranchSource()
279 GetRemoteBranch(m_BranchSource
.GetString());
282 void CPushDlg::OnBnClickedOk()
284 CHorizontalResizableStandAloneDialog::UpdateData(TRUE
);
286 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_REMOTE
)
288 m_URL
=m_Remote
.GetString();
290 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_URL
)
292 m_URL
=m_RemoteURL
.GetString();
295 if (!m_bPushAllBranches
)
297 this->m_BranchRemoteName
=m_BranchRemote
.GetString().Trim();
298 this->m_BranchSourceName
=m_BranchSource
.GetString().Trim();
300 if (m_BranchSourceName
.IsEmpty() && m_BranchRemoteName
.IsEmpty())
302 if (CMessageBox::Show(NULL
, IDS_B_T_BOTHEMPTY
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
) == IDNO
)
305 if (m_BranchSourceName
.IsEmpty() && !m_BranchRemoteName
.IsEmpty())
307 if (CMessageBox::Show(NULL
, IDS_B_T_LOCALEMPTY
, IDS_APPNAME
, MB_ICONEXCLAMATION
| MB_YESNO
) == IDNO
)
310 else if (!m_BranchRemoteName
.IsEmpty() && !g_Git
.IsBranchNameValid(this->m_BranchRemoteName
))
312 CMessageBox::Show(NULL
, IDS_B_T_INVALID
, IDS_APPNAME
, MB_OK
);
317 // do not store branch names on removal
318 this->m_RemoteURL
.SaveHistory();
319 this->m_BranchRemote
.SaveHistory();
320 m_RemoteReg
= m_Remote
.GetString();
324 this->m_regAutoLoad
= m_bAutoLoad
;
326 CHorizontalResizableStandAloneDialog::OnOK();
329 void CPushDlg::OnBnClickedRemoteManage()
331 CAppUtils::LaunchRemoteSetting();
335 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
337 switch (m_BrowseLocalRef
.GetCurrentEntry())
339 case 0: /* Browse Refence*/
341 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource
, gPickRef_Head
))
342 OnCbnSelchangeBranchSource();
350 if(dlg
.DoModal() == IDOK
)
352 if (dlg
.GetSelectedHash().IsEmpty())
355 m_BranchSource
.SetWindowText(dlg
.GetSelectedHash());
356 OnCbnSelchangeBranchSource();
364 if(dlg
.DoModal() == IDOK
)
366 m_BranchSource
.SetWindowText(dlg
.m_SelectedHash
);
367 OnCbnSelchangeBranchSource();
374 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
376 CString remoteBranchName
;
378 m_BranchRemote
.GetWindowText(remoteBranchName
);
379 remoteName
= m_Remote
.GetString();
380 remoteBranchName
= remoteName
+ '/' + remoteBranchName
;
381 remoteBranchName
= CBrowseRefsDlg::PickRef(false, remoteBranchName
, gPickRef_Remote
);
382 if(remoteBranchName
.IsEmpty())
384 remoteBranchName
= remoteBranchName
.Mid(13);//Strip 'refs/remotes/'
385 int slashPlace
= remoteBranchName
.Find('/');
386 remoteName
= remoteBranchName
.Left(slashPlace
);
387 remoteBranchName
= remoteBranchName
.Mid(slashPlace
+ 1); //Strip remote name (for example 'origin/')
390 int remoteSel
= m_Remote
.FindStringExact(0,remoteName
);
392 m_Remote
.SetCurSel(remoteSel
);
395 m_BranchRemote
.AddString(remoteBranchName
);
398 BOOL
CPushDlg::PreTranslateMessage(MSG
* pMsg
)
400 if (pMsg
->message
== WM_KEYDOWN
)
402 switch (pMsg
->wParam
)
412 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg
);
415 void CPushDlg::OnBnClickedPushall()
418 this->GetDlgItem(IDC_BRANCH_REMOTE
)->EnableWindow(!m_bPushAllBranches
);
419 this->GetDlgItem(IDC_BRANCH_SOURCE
)->EnableWindow(!m_bPushAllBranches
);
420 this->GetDlgItem(IDC_BUTTON_BROWSE_SOURCE_BRANCH
)->EnableWindow(!m_bPushAllBranches
);
421 this->GetDlgItem(IDC_BUTTON_BROWSE_DEST_BRANCH
)->EnableWindow(!m_bPushAllBranches
);
422 this->GetDlgItem(IDC_TAGS
)->EnableWindow(!m_bPushAllBranches
);
423 if (m_bTags
&& m_bPushAllBranches
)