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 // PullFetchDlg.cpp : implementation file
24 #include "TortoiseProc.h"
25 #include "PullFetchDlg.h"
28 #include "BrowseRefsDlg.h"
29 // CPullFetchDlg dialog
31 IMPLEMENT_DYNAMIC(CPullFetchDlg
, CResizableStandAloneDialog
)
33 CPullFetchDlg::CPullFetchDlg(CWnd
* pParent
/*=NULL*/)
34 : CResizableStandAloneDialog(CPullFetchDlg::IDD
, pParent
)
37 m_bAutoLoad
= CAppUtils::IsSSHPutty();
38 m_bAutoLoadEnable
=CAppUtils::IsSSHPutty();;
42 CPullFetchDlg::~CPullFetchDlg()
46 void CPullFetchDlg::DoDataExchange(CDataExchange
* pDX
)
48 CDialog::DoDataExchange(pDX
);
49 DDX_Control(pDX
, IDC_REMOTE_COMBO
, this->m_Remote
);
50 DDX_Control(pDX
, IDC_OTHER
, this->m_Other
);
51 DDX_Control(pDX
, IDC_REMOTE_BRANCH
, this->m_RemoteBranch
);
52 DDX_Control(pDX
,IDC_REMOTE_MANAGE
, this->m_RemoteManage
);
53 DDX_Check(pDX
,IDC_PUTTYKEY_AUTOLOAD
,m_bAutoLoad
);
54 DDX_Check(pDX
,IDC_CHECK_REBASE
,m_bRebase
);
55 DDX_Check(pDX
,IDC_CHECK_PRUNE
,m_bPrune
);
59 BEGIN_MESSAGE_MAP(CPullFetchDlg
,CResizableStandAloneDialog
)
60 ON_BN_CLICKED(IDC_REMOTE_RD
, &CPullFetchDlg::OnBnClickedRd
)
61 ON_BN_CLICKED(IDC_OTHER_RD
, &CPullFetchDlg::OnBnClickedRd
)
62 ON_BN_CLICKED(IDOK
, &CPullFetchDlg::OnBnClickedOk
)
63 ON_STN_CLICKED(IDC_REMOTE_MANAGE
, &CPullFetchDlg::OnStnClickedRemoteManage
)
64 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF
, &CPullFetchDlg::OnBnClickedButtonBrowseRef
)
67 BOOL
CPullFetchDlg::OnInitDialog()
69 CResizableStandAloneDialog::OnInitDialog();
70 AddAnchor(IDC_REMOTE_COMBO
, TOP_LEFT
, TOP_RIGHT
);
71 AddAnchor(IDC_OTHER
, TOP_LEFT
,TOP_RIGHT
);
73 AddAnchor(IDC_REMOTE_BRANCH
, TOP_LEFT
,TOP_RIGHT
);
74 AddAnchor(IDC_BUTTON_BROWSE_REF
,TOP_RIGHT
);
76 AddAnchor(IDOK
,BOTTOM_RIGHT
);
77 AddAnchor(IDCANCEL
,BOTTOM_RIGHT
);
78 AddAnchor(IDC_GROUPT_REMOTE
,TOP_LEFT
,BOTTOM_RIGHT
);
79 AddAnchor(IDC_PUTTYKEY_AUTOLOAD
,BOTTOM_LEFT
);
80 AddAnchor(IDC_CHECK_PRUNE
,BOTTOM_LEFT
);
81 AddAnchor(IDC_CHECK_REBASE
,BOTTOM_LEFT
);
82 AddAnchor(IDC_REMOTE_MANAGE
,BOTTOM_LEFT
);
83 AddAnchor(IDHELP
, BOTTOM_RIGHT
);
85 CString WorkingDir
=g_Git
.m_CurrentDir
;
86 WorkingDir
.Replace(_T(':'),_T('_'));
88 m_RemoteReg
= CRegString(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir
));
90 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir
,this->m_IsPull
);
91 m_regRebase
=CRegDWORD(regkey
,false);
92 regkey
.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\autoload"),WorkingDir
,this->m_IsPull
);
94 m_regAutoLoadPutty
= CRegDWORD(regkey
,this->m_bAutoLoad
);
95 m_bAutoLoad
= m_regAutoLoadPutty
;
97 if(!CAppUtils::IsSSHPutty())
102 this->m_bRebase
= m_regRebase
;
106 GetDlgItem(IDC_CHECK_REBASE
)->ShowWindow(SW_HIDE
);
107 this->m_bRebase
= FALSE
;
110 this->UpdateData(FALSE
);
112 this->AddOthersToAnchor();
114 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD
)->EnableWindow(m_bAutoLoadEnable
);
116 CheckRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
,IDC_REMOTE_RD
);
117 m_Remote
.EnableWindow(TRUE
);
118 m_Other
.EnableWindow(FALSE
);
120 m_RemoteBranch
.EnableWindow(FALSE
);
123 GetDlgItem(IDC_CHECK_REBASE
)->ShowWindow(SW_HIDE
);
124 GetDlgItem(IDC_CHECK_PRUNE
)->ShowWindow(SW_HIDE
);
127 m_Other
.SetURLHistory(TRUE
);
128 m_Other
.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
129 CString clippath
=CAppUtils::GetClipboardLink();
130 if(clippath
.IsEmpty())
131 m_Other
.SetCurSel(0);
133 m_Other
.SetWindowText(clippath
);
135 m_RemoteBranch
.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
136 m_RemoteBranch
.SetCurSel(0);
139 this->SetWindowTextW(CString(_T("Pull - ")) + g_Git
.m_CurrentDir
);
141 this->SetWindowTextW(CString(_T("Fetch - ")) + g_Git
.m_CurrentDir
);
145 EnableSaveRestore(_T("PullFetchDlg"));
146 this->m_RemoteManage
.SetURL(CString());
150 void CPullFetchDlg::Refresh()
152 //Select pull-remote from current branch
153 CString currentBranch
= g_Git
.GetSymbolicRef();
155 configName
.Format(L
"branch.%s.remote", currentBranch
);
156 CString pullRemote
= this->m_configPullRemote
= g_Git
.GetConfigValue(configName
);
158 //Select pull-branch from current branch
159 configName
.Format(L
"branch.%s.merge", currentBranch
);
160 CString pullBranch
= m_configPullBranch
= CGit::StripRefName(g_Git
.GetConfigValue(configName
));
161 m_RemoteBranch
.AddString(pullBranch
);
163 if(pullRemote
.IsEmpty())
164 pullRemote
= m_RemoteReg
;
166 if (!m_PreSelectRemote
.IsEmpty())
167 pullRemote
= m_PreSelectRemote
;
171 if(!g_Git
.GetRemoteList(list
))
173 for(unsigned int i
=0;i
<list
.size();i
++)
175 m_Remote
.AddString(list
[i
]);
176 if(list
[i
] == pullRemote
)
180 m_Remote
.SetCurSel(sel
);
182 // CPullFetchDlg message handlers
184 void CPullFetchDlg::OnBnClickedRd()
186 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_REMOTE_RD
)
188 m_Remote
.EnableWindow(TRUE
);
189 m_Other
.EnableWindow(FALSE
);
191 m_RemoteBranch
.EnableWindow(FALSE
);
193 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_OTHER_RD
)
195 m_Remote
.EnableWindow(FALSE
);
196 m_Other
.EnableWindow(TRUE
);;
198 m_RemoteBranch
.EnableWindow(TRUE
);
202 void CPullFetchDlg::OnBnClickedOk()
205 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_REMOTE_RD
)
207 m_RemoteURL
=m_Remote
.GetString();
209 (m_configPullRemote
== m_RemoteURL
&& m_configPullBranch
== m_RemoteBranch
.GetString() ))
210 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
211 //because otherwise git will not update the remote tracking branches.
212 m_RemoteBranchName
.Empty();
214 m_RemoteBranchName
=m_RemoteBranch
.GetString();
216 if( GetCheckedRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
) == IDC_OTHER_RD
)
218 m_Other
.GetWindowTextW(m_RemoteURL
);
219 m_RemoteBranchName
=m_RemoteBranch
.GetString();
222 m_RemoteReg
= m_Remote
.GetString();
224 m_Other
.SaveHistory();
225 m_RemoteBranch
.SaveHistory();
226 this->m_regRebase
=this->m_bRebase
;
228 m_regAutoLoadPutty
= m_bAutoLoad
;
233 void CPullFetchDlg::OnStnClickedRemoteManage()
235 CAppUtils::LaunchRemoteSetting();
239 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
242 initialRef
.Format(L
"refs/remotes/%s/%s", m_Remote
.GetString(), m_RemoteBranch
.GetString());
243 CString selectedRef
= CBrowseRefsDlg::PickRef(false, initialRef
, gPickRef_Remote
);
244 if(selectedRef
.Left(13) != "refs/remotes/")
247 selectedRef
= selectedRef
.Mid(13);
248 int ixSlash
= selectedRef
.Find('/');
250 CString remoteName
= selectedRef
.Left(ixSlash
);
251 CString remoteBranch
= selectedRef
.Mid(ixSlash
+ 1);
253 int ixFound
= m_Remote
.FindStringExact(0, remoteName
);
255 m_Remote
.SetCurSel(ixFound
);
256 m_RemoteBranch
.AddString(remoteBranch
);
258 CheckRadioButton(IDC_REMOTE_RD
,IDC_OTHER_RD
,IDC_REMOTE_RD
);