1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2011 - 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"
30 #include "BrowseRefsDlg.h"
31 #include "MessageBox.h"
35 IMPLEMENT_DYNAMIC(CPushDlg
, CHorizontalResizableStandAloneDialog
)
37 CPushDlg::CPushDlg(CWnd
* pParent
/*=NULL*/)
38 : CHorizontalResizableStandAloneDialog(CPushDlg::IDD
, pParent
)
39 , m_bPushAllBranches(FALSE
)
45 m_bAutoLoad
= CAppUtils::IsSSHPutty();
52 void CPushDlg::DoDataExchange(CDataExchange
* pDX
)
54 CHorizontalResizableStandAloneDialog::DoDataExchange(pDX
);
55 DDX_Control(pDX
, IDC_BRANCH_REMOTE
, this->m_BranchRemote
);
56 DDX_Control(pDX
, IDC_BRANCH_SOURCE
, this->m_BranchSource
);
57 DDX_Control(pDX
, IDC_REMOTE
, this->m_Remote
);
58 DDX_Control(pDX
, IDC_URL
, this->m_RemoteURL
);
59 DDX_Check(pDX
,IDC_FORCE
,this->m_bForce
);
60 DDX_Check(pDX
,IDC_PUSHALL
,this->m_bPushAllBranches
);
61 DDX_Check(pDX
,IDC_PACK
,this->m_bPack
);
62 DDX_Check(pDX
,IDC_TAGS
,this->m_bTags
);
63 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
,this->m_bAutoLoad
);
66 BEGIN_MESSAGE_MAP(CPushDlg
, CHorizontalResizableStandAloneDialog
)
67 ON_BN_CLICKED(IDC_RD_REMOTE
, &CPushDlg::OnBnClickedRd
)
68 ON_BN_CLICKED(IDC_RD_URL
, &CPushDlg::OnBnClickedRd
)
69 ON_CBN_SELCHANGE(IDC_BRANCH_SOURCE
, &CPushDlg::OnCbnSelchangeBranchSource
)
70 ON_BN_CLICKED(IDOK
, &CPushDlg::OnBnClickedOk
)
71 ON_BN_CLICKED(IDC_REMOTE_MANAGE
, &CPushDlg::OnBnClickedRemoteManage
)
72 ON_BN_CLICKED(IDC_BUTTON_BROWSE_SOURCE_BRANCH
, &CPushDlg::OnBnClickedButtonBrowseSourceBranch
)
73 ON_BN_CLICKED(IDC_BUTTON_BROWSE_DEST_BRANCH
, &CPushDlg::OnBnClickedButtonBrowseDestBranch
)
74 ON_BN_CLICKED(IDC_PUSHALL
, &CPushDlg::OnBnClickedPushall
)
77 BOOL
CPushDlg::OnInitDialog()
79 CHorizontalResizableStandAloneDialog::OnInitDialog();
80 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
82 AddAnchor(IDOK
,BOTTOM_RIGHT
);
83 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
84 AddAnchor(IDC_BRANCH_GROUP
, TOP_LEFT
,TOP_RIGHT
);
85 AddAnchor(IDC_STATIC_REMOTE
, TOP_LEFT
);
86 AddAnchor(IDC_STATIC_SOURCE
, TOP_LEFT
);
88 AddAnchor(IDC_PUSHALL
, TOP_LEFT
);
89 AddAnchor(IDC_BRANCH_REMOTE
, TOP_LEFT
, TOP_RIGHT
);
90 AddAnchor(IDC_BUTTON_BROWSE_DEST_BRANCH
, TOP_RIGHT
);
91 AddAnchor(IDC_BRANCH_SOURCE
, TOP_LEFT
, TOP_RIGHT
);
92 AddAnchor(IDC_BUTTON_BROWSE_SOURCE_BRANCH
, TOP_RIGHT
);
94 AddAnchor(IDC_URL_GROUP
, TOP_LEFT
,TOP_RIGHT
);
95 AddAnchor(IDC_RD_REMOTE
, TOP_LEFT
);
96 AddAnchor(IDC_RD_URL
, TOP_LEFT
);
98 AddAnchor(IDC_REMOTE
, TOP_LEFT
, TOP_RIGHT
);
100 AddAnchor(IDC_URL
, TOP_LEFT
,TOP_RIGHT
);
102 AddAnchor(IDC_OPTION_GROUP
, TOP_LEFT
,TOP_RIGHT
);
104 AddAnchor(IDC_FORCE
, TOP_LEFT
);
105 AddAnchor(IDC_PACK
, TOP_LEFT
);
106 AddAnchor(IDC_TAGS
, TOP_LEFT
);
107 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,TOP_LEFT
);
109 AddAnchor(IDC_REMOTE_MANAGE
,TOP_RIGHT
);
110 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
114 CString sWindowTitle
;
115 GetWindowText(sWindowTitle
);
116 CAppUtils::SetWindowTitle(m_hWnd
, g_Git
.m_CurrentDir
, sWindowTitle
);
118 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow(CAppUtils::IsSSHPutty());
120 EnableSaveRestore(_T("PushDlg"));
122 m_RemoteURL
.SetURLHistory(TRUE
);
124 CString WorkingDir
=g_Git
.m_CurrentDir
;
125 WorkingDir
.Replace(_T(':'),_T('_'));
126 m_RemoteURL
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\PushURLS\\"))+WorkingDir
, _T("url"));
127 CString clippath
=CAppUtils::GetClipboardLink();
128 if(clippath
.IsEmpty())
129 m_RemoteURL
.SetCurSel(0);
131 m_RemoteURL
.SetWindowText(clippath
);
133 m_RemoteURL
.EnableWindow(FALSE
);
134 CheckRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
,IDC_RD_REMOTE
);
137 this->m_regAutoLoad
= CRegDWORD(CString(_T("Software\\TortoiseGit\\History\\PushDlgAutoLoad\\"))+WorkingDir
,
139 m_bAutoLoad
= this->m_regAutoLoad
;
140 if(!CAppUtils::IsSSHPutty())
146 //m_BranchRemote.SetWindowTextW(m_BranchSource.GetString());
148 this->UpdateData(false);
152 void CPushDlg::Refresh()
154 CString WorkingDir
=g_Git
.m_CurrentDir
;
155 WorkingDir
.Replace(_T(':'),_T('_'));
157 CRegString
remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir
));
158 m_RemoteReg
= remote
;
164 if(!g_Git
.GetRemoteList(list
))
166 for(unsigned int i
=0;i
<list
.size();i
++)
168 m_Remote
.AddString(list
[i
]);
169 if(list
[i
] == remote
)
173 m_Remote
.SetCurSel(sel
);
177 m_BranchSource
.Reset();
178 m_BranchSource
.AddString(_T(" ")); // empty string does not work, for removal of remote branches/tags
179 m_BranchSource
.SetMaxHistoryItems(0x7FFFFFFF);
180 if(!g_Git
.GetBranchList(list
,¤t
))
182 for(unsigned int i
=0;i
<list
.size();i
++)
183 m_BranchSource
.AddString(list
[i
]);
184 current
++; // shift for " "
186 if (wcsncmp(m_BranchSourceName
, _T("refs/"), 5) == 0)
187 m_BranchSourceName
= m_BranchSourceName
.Mid(5);
188 if (wcsncmp(m_BranchSourceName
, _T("heads/"), 6) == 0)
190 m_BranchSourceName
= m_BranchSourceName
.Mid(6);
191 m_BranchSource
.SetCurSel(m_BranchSource
.FindStringExact(-1, m_BranchSourceName
));
193 else if (wcsncmp(m_BranchSourceName
, _T("remotes/"), 8) == 0)
194 m_BranchSource
.SetCurSel(m_BranchSource
.FindStringExact(-1, m_BranchSourceName
));
196 m_BranchSource
.SetCurSel(current
);
198 GetRemoteBranch(m_BranchSource
.GetString());
200 this->GetDlgItem(IDOK
)->EnableWindow(m_BranchSource
.GetCount() != 0);
203 void CPushDlg::GetRemoteBranch(CString currentBranch
)
205 CString WorkingDir
=g_Git
.m_CurrentDir
;
206 WorkingDir
.Replace(_T(':'), _T('_'));
208 if (currentBranch
.IsEmpty())
213 configName
.Format(L
"branch.%s.pushremote", currentBranch
);
214 CString pushRemote
= g_Git
.GetConfigValue(configName
);
215 if( pushRemote
.IsEmpty() )
217 configName
.Format(L
"branch.%s.remote", currentBranch
);
218 pushRemote
= g_Git
.GetConfigValue(configName
);
221 CRegString
remote(CString(_T("Software\\TortoiseGit\\History\\PushRemote\\")+WorkingDir
));
223 if( !pushRemote
.IsEmpty() )
226 //Select pull-branch from current branch
227 configName
.Format(L
"branch.%s.pushbranch", currentBranch
);
228 CString pushBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
229 if( pushBranch
.IsEmpty() )
231 configName
.Format(L
"branch.%s.merge", currentBranch
);
232 pushBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
235 m_BranchRemote
.LoadHistory(CString(_T("Software\\TortoiseGit\\History\\RemoteBranch\\"))+WorkingDir
, _T("branch"));
236 if( !pushBranch
.IsEmpty() )
237 m_BranchRemote
.AddString(pushBranch
);
240 // CPushDlg message handlers
242 void CPushDlg::OnBnClickedRd()
244 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_REMOTE
)
246 m_Remote
.EnableWindow(TRUE
);
247 GetDlgItem(IDC_REMOTE_MANAGE
)->EnableWindow(TRUE
);
248 m_RemoteURL
.EnableWindow(FALSE
);
250 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_URL
)
252 m_Remote
.EnableWindow(FALSE
);
253 GetDlgItem(IDC_REMOTE_MANAGE
)->EnableWindow(FALSE
);
254 m_RemoteURL
.EnableWindow(TRUE
);
259 void CPushDlg::OnCbnSelchangeBranchSource()
261 GetRemoteBranch(m_BranchSource
.GetString());
264 void CPushDlg::OnBnClickedOk()
266 CHorizontalResizableStandAloneDialog::UpdateData(TRUE
);
268 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_REMOTE
)
270 m_URL
=m_Remote
.GetString();
272 if( GetCheckedRadioButton(IDC_RD_REMOTE
,IDC_RD_URL
) == IDC_RD_URL
)
274 m_URL
=m_RemoteURL
.GetString();
277 if (!m_bPushAllBranches
)
279 this->m_BranchRemoteName
=m_BranchRemote
.GetString().Trim();
280 this->m_BranchSourceName
=m_BranchSource
.GetString().Trim();
282 if (m_BranchSourceName
.IsEmpty() && m_BranchRemoteName
.IsEmpty())
284 if (CMessageBox::Show(NULL
, IDS_B_T_BOTHEMPTY
, IDS_APPNAME
, MB_ICONQUESTION
| MB_YESNO
) == IDNO
)
287 if (m_BranchSourceName
.IsEmpty() && !m_BranchRemoteName
.IsEmpty())
289 if (CMessageBox::Show(NULL
, IDS_B_T_LOCALEMPTY
, IDS_APPNAME
, MB_ICONEXCLAMATION
| MB_YESNO
) == IDNO
)
292 else if (!m_BranchRemoteName
.IsEmpty() && !g_Git
.IsBranchNameValid(this->m_BranchRemoteName
))
294 CMessageBox::Show(NULL
, IDS_B_T_INVALID
, IDS_APPNAME
, MB_OK
);
299 // do not store branch names on removal
300 this->m_RemoteURL
.SaveHistory();
301 this->m_BranchRemote
.SaveHistory();
302 m_RemoteReg
= m_Remote
.GetString();
306 this->m_regAutoLoad
= m_bAutoLoad
;
308 CHorizontalResizableStandAloneDialog::OnOK();
311 void CPushDlg::OnBnClickedRemoteManage()
313 CAppUtils::LaunchRemoteSetting();
317 void CPushDlg::OnBnClickedButtonBrowseSourceBranch()
319 if(CBrowseRefsDlg::PickRefForCombo(&m_BranchSource
, gPickRef_Head
))
320 OnCbnSelchangeBranchSource();
323 void CPushDlg::OnBnClickedButtonBrowseDestBranch()
325 CString remoteBranchName
;
327 m_BranchRemote
.GetWindowText(remoteBranchName
);
328 remoteName
= m_Remote
.GetString();
329 remoteBranchName
= remoteName
+ '/' + remoteBranchName
;
330 remoteBranchName
= CBrowseRefsDlg::PickRef(false, remoteBranchName
, gPickRef_Remote
);
331 if(remoteBranchName
.IsEmpty())
333 remoteBranchName
= remoteBranchName
.Mid(13);//Strip 'refs/remotes/'
334 int slashPlace
= remoteBranchName
.Find('/');
335 remoteName
= remoteBranchName
.Left(slashPlace
);
336 remoteBranchName
= remoteBranchName
.Mid(slashPlace
+ 1); //Strip remote name (for example 'origin/')
339 int remoteSel
= m_Remote
.FindStringExact(0,remoteName
);
341 m_Remote
.SetCurSel(remoteSel
);
344 m_BranchRemote
.AddString(remoteBranchName
);
347 BOOL
CPushDlg::PreTranslateMessage(MSG
* pMsg
)
349 if (pMsg
->message
== WM_KEYDOWN
)
351 switch (pMsg
->wParam
)
361 return CHorizontalResizableStandAloneDialog::PreTranslateMessage(pMsg
);
364 void CPushDlg::OnBnClickedPushall()
367 this->GetDlgItem(IDC_BRANCH_REMOTE
)->EnableWindow(!m_bPushAllBranches
);
368 this->GetDlgItem(IDC_BRANCH_SOURCE
)->EnableWindow(!m_bPushAllBranches
);
369 this->GetDlgItem(IDC_BUTTON_BROWSE_SOURCE_BRANCH
)->EnableWindow(!m_bPushAllBranches
);
370 this->GetDlgItem(IDC_BUTTON_BROWSE_DEST_BRANCH
)->EnableWindow(!m_bPushAllBranches
);
371 this->GetDlgItem(IDC_TAGS
)->EnableWindow(!m_bPushAllBranches
);
372 if (m_bTags
&& m_bPushAllBranches
)