1 // PullFetchDlg.cpp : implementation file
\r
5 #include "TortoiseProc.h"
\r
6 #include "PullFetchDlg.h"
\r
8 #include "AppUtils.h"
\r
9 #include "BrowseRefsDlg.h"
\r
10 // CPullFetchDlg dialog
\r
12 IMPLEMENT_DYNAMIC(CPullFetchDlg, CResizableStandAloneDialog)
\r
14 CPullFetchDlg::CPullFetchDlg(CWnd* pParent /*=NULL*/)
\r
15 : CResizableStandAloneDialog(CPullFetchDlg::IDD, pParent)
\r
18 m_bAutoLoad = CAppUtils::IsSSHPutty();
\r
19 m_bAutoLoadEnable=true;
\r
20 m_regRebase = false;
\r
23 CPullFetchDlg::~CPullFetchDlg()
\r
27 void CPullFetchDlg::DoDataExchange(CDataExchange* pDX)
\r
29 CDialog::DoDataExchange(pDX);
\r
30 DDX_Control(pDX, IDC_REMOTE_COMBO, this->m_Remote);
\r
31 DDX_Control(pDX, IDC_OTHER, this->m_Other);
\r
32 DDX_Control(pDX, IDC_REMOTE_BRANCH, this->m_RemoteBranch);
\r
33 DDX_Control(pDX,IDC_REMOTE_MANAGE, this->m_RemoteManage);
\r
34 DDX_Check(pDX,IDC_PUTTYKEY_AUTOLOAD,m_bAutoLoad);
\r
35 DDX_Check(pDX,IDC_CHECK_REBASE,m_bRebase);
\r
40 BEGIN_MESSAGE_MAP(CPullFetchDlg,CResizableStandAloneDialog )
\r
41 ON_BN_CLICKED(IDC_REMOTE_RD, &CPullFetchDlg::OnBnClickedRd)
\r
42 ON_BN_CLICKED(IDC_OTHER_RD, &CPullFetchDlg::OnBnClickedRd)
\r
43 ON_BN_CLICKED(IDOK, &CPullFetchDlg::OnBnClickedOk)
\r
44 ON_STN_CLICKED(IDC_REMOTE_MANAGE, &CPullFetchDlg::OnStnClickedRemoteManage)
\r
45 ON_BN_CLICKED(IDC_BUTTON_BROWSE_REF, &CPullFetchDlg::OnBnClickedButtonBrowseRef)
\r
48 BOOL CPullFetchDlg::OnInitDialog()
\r
50 CResizableStandAloneDialog::OnInitDialog();
\r
51 AddAnchor(IDC_REMOTE_COMBO, TOP_LEFT, TOP_RIGHT);
\r
52 AddAnchor(IDC_OTHER, TOP_LEFT,TOP_RIGHT);
\r
54 AddAnchor(IDC_REMOTE_BRANCH, TOP_LEFT,TOP_RIGHT);
\r
56 AddAnchor(IDOK,BOTTOM_RIGHT);
\r
57 AddAnchor(IDCANCEL,BOTTOM_RIGHT);
\r
58 AddAnchor(IDC_GROUPT_REMOTE,TOP_LEFT,BOTTOM_RIGHT);
\r
59 AddAnchor(IDC_PUTTYKEY_AUTOLOAD,BOTTOM_LEFT);
\r
60 AddAnchor(IDC_CHECK_REBASE,BOTTOM_LEFT);
\r
61 AddAnchor(IDC_REMOTE_MANAGE,BOTTOM_LEFT);
\r
62 AddAnchor(IDHELP, BOTTOM_RIGHT);
\r
64 CString WorkingDir=g_Git.m_CurrentDir;
\r
65 WorkingDir.Replace(_T(':'),_T('_'));
\r
68 regkey.Format(_T("Software\\TortoiseGit\\TortoiseProc\\PullFetch\\%s_%d\\rebase"),WorkingDir,this->m_IsPull);
\r
69 m_regRebase=CRegDWORD(regkey,false);
\r
71 this->m_bRebase = m_regRebase;
\r
73 this->UpdateData(FALSE);
\r
75 this->AddOthersToAnchor();
\r
77 this->GetDlgItem(IDC_PUTTYKEY_AUTOLOAD)->EnableWindow(m_bAutoLoadEnable);
\r
79 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
\r
80 m_Remote.EnableWindow(TRUE);
\r
81 m_Other.EnableWindow(FALSE);
\r
83 m_RemoteBranch.EnableWindow(FALSE);
\r
86 GetDlgItem(IDC_CHECK_REBASE)->ShowWindow(SW_HIDE);
\r
88 m_Other.SetURLHistory(TRUE);
\r
89 m_Other.LoadHistory(_T("Software\\TortoiseGit\\History\\PullURLS"), _T("url"));
\r
90 CString clippath=CAppUtils::GetClipboardLink();
\r
91 if(clippath.IsEmpty())
\r
92 m_Other.SetCurSel(0);
\r
94 m_Other.SetWindowText(clippath);
\r
96 m_RemoteBranch.LoadHistory(_T("Software\\TortoiseGit\\History\\PullRemoteBranch"), _T("br"));
\r
97 m_RemoteBranch.SetCurSel(0);
\r
100 this->SetWindowTextW(CString(_T("Pull - "))+WorkingDir);
\r
102 this->SetWindowTextW(CString(_T("Fetch - "))+WorkingDir);
\r
104 STRING_VECTOR list;
\r
106 CRegString remote(CString(_T("Software\\TortoiseGit\\History\\PullRemote\\")+WorkingDir));
\r
107 m_RemoteReg = remote;
\r
110 //Select pull-remote from current branch
\r
111 CString currentBranch = g_Git.GetSymbolicRef();
\r
112 CString configName;
\r
113 configName.Format(L"branch.%s.remote", currentBranch);
\r
114 CString pullRemote = m_configPullRemote = g_Git.GetConfigValue(configName);
\r
116 //Select pull-branch from current branch
\r
117 configName.Format(L"branch.%s.merge", currentBranch);
\r
118 CString pullBranch = m_configPullBranch = CGit::StripRefName(g_Git.GetConfigValue(configName));
\r
119 m_RemoteBranch.AddString(pullBranch);
\r
121 if(pullRemote.IsEmpty())
\r
122 pullRemote = remote;
\r
124 if(!g_Git.GetRemoteList(list))
\r
126 for(unsigned int i=0;i<list.size();i++)
\r
128 m_Remote.AddString(list[i]);
\r
129 if(list[i] == pullRemote)
\r
133 m_Remote.SetCurSel(sel);
\r
135 EnableSaveRestore(_T("PullFetchDlg"));
\r
136 this->m_RemoteManage.SetURL(CString());
\r
139 // CPullFetchDlg message handlers
\r
141 void CPullFetchDlg::OnBnClickedRd()
\r
144 // TODO: Add your control notification handler code here
\r
145 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
\r
147 m_Remote.EnableWindow(TRUE);
\r
148 m_Other.EnableWindow(FALSE);
\r
150 m_RemoteBranch.EnableWindow(FALSE);
\r
152 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
\r
154 m_Remote.EnableWindow(FALSE);
\r
155 m_Other.EnableWindow(TRUE);;
\r
157 m_RemoteBranch.EnableWindow(TRUE);
\r
163 void CPullFetchDlg::OnBnClickedOk()
\r
165 this->UpdateData();
\r
166 // TODO: Add your control notification handler code here
\r
167 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_REMOTE_RD)
\r
169 m_RemoteURL=m_Remote.GetString();
\r
171 (m_configPullRemote == m_RemoteURL && m_configPullBranch == m_RemoteBranch.GetString() ))
\r
172 //When fetching or when pulling from the configured tracking branch, dont explicitly set the remote branch name,
\r
173 //because otherwise git will not update the remote tracking branches.
\r
174 m_RemoteBranchName.Empty();
\r
176 m_RemoteBranchName=m_RemoteBranch.GetString();
\r
179 if( GetCheckedRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD) == IDC_OTHER_RD)
\r
181 m_Other.GetWindowTextW(m_RemoteURL);
\r
182 m_RemoteBranchName=m_RemoteBranch.GetString();
\r
186 m_RemoteReg = m_Remote.GetString();
\r
188 m_Other.SaveHistory();
\r
189 m_RemoteBranch.SaveHistory();
\r
190 this->m_regRebase=this->m_bRebase;
\r
195 void CPullFetchDlg::OnStnClickedRemoteManage()
\r
197 // TODO: Add your control notification handler code here
\r
198 CAppUtils::LaunchRemoteSetting();
\r
201 void CPullFetchDlg::OnBnClickedButtonBrowseRef()
\r
203 CString initialRef;
\r
204 initialRef.Format(L"refs/remotes/%s/%s", m_Remote.GetString(), m_RemoteBranch.GetString());
\r
205 CString selectedRef = CBrowseRefsDlg::PickRef(false, initialRef, gPickRef_Remote);
\r
206 if(selectedRef.Left(13) != "refs/remotes/")
\r
209 selectedRef = selectedRef.Mid(13);
\r
210 int ixSlash = selectedRef.Find('/');
\r
212 CString remoteName = selectedRef.Left(ixSlash);
\r
213 CString remoteBranch = selectedRef.Mid(ixSlash + 1);
\r
215 int ixFound = m_Remote.FindStringExact(0, remoteName);
\r
217 m_Remote.SetCurSel(ixFound);
\r
218 m_RemoteBranch.AddString(remoteBranch);
\r
220 CheckRadioButton(IDC_REMOTE_RD,IDC_OTHER_RD,IDC_REMOTE_RD);
\r