No need to explicitly initialize CString and use Empty() for clearing CString
[TortoiseGit.git] / src / TortoiseProc / Settings / SettingGitRemote.cpp
blob0bfaec8cd2b718ab5a53cb3f613e003135c388d5
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2015 - 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.
19 // SettingGitRemote.cpp : implementation file
22 #include "stdafx.h"
23 #include "TortoiseProc.h"
24 #include "SettingGitRemote.h"
25 #include "Settings.h"
26 #include "GitAdminDir.h"
27 #include "MessageBox.h"
28 #include "AppUtils.h"
29 #include "Git.h"
30 #include "HistoryCombo.h"
32 // CSettingGitRemote dialog
34 IMPLEMENT_DYNAMIC(CSettingGitRemote, ISettingsPropPage)
36 CSettingGitRemote::CSettingGitRemote()
37 : ISettingsPropPage(CSettingGitRemote::IDD)
38 , m_bNoFetch(false)
39 , m_bPrune(2)
40 , m_bPruneAll(FALSE)
41 , m_bPushDefault(FALSE)
44 m_ChangedMask = 0;
47 CSettingGitRemote::~CSettingGitRemote()
51 void CSettingGitRemote::DoDataExchange(CDataExchange* pDX)
53 CPropertyPage::DoDataExchange(pDX);
54 DDX_Control(pDX, IDC_LIST_REMOTE, m_ctrlRemoteList);
55 DDX_Text(pDX, IDC_EDIT_REMOTE, m_strRemote);
56 DDX_Text(pDX, IDC_EDIT_URL, m_strUrl);
57 DDX_Text(pDX, IDC_EDIT_PUSHURL, m_strPushUrl);
58 DDX_Text(pDX, IDC_EDIT_PUTTY_KEY, m_strPuttyKeyfile);
59 DDX_Control(pDX, IDC_COMBO_TAGOPT, m_ctrlTagOpt);
60 DDX_Check(pDX, IDC_CHECK_PRUNE, m_bPrune);
61 DDX_Check(pDX, IDC_CHECK_PRUNEALL, m_bPruneAll);
62 DDX_Check(pDX, IDC_CHECK_PUSHDEFAULT, m_bPushDefault);
66 BEGIN_MESSAGE_MAP(CSettingGitRemote, CPropertyPage)
67 ON_WM_TIMER()
68 ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CSettingGitRemote::OnBnClickedButtonBrowse)
69 ON_BN_CLICKED(IDC_BUTTON_ADD, &CSettingGitRemote::OnBnClickedButtonAdd)
70 ON_LBN_SELCHANGE(IDC_LIST_REMOTE, &CSettingGitRemote::OnLbnSelchangeListRemote)
71 ON_EN_CHANGE(IDC_EDIT_REMOTE, &CSettingGitRemote::OnEnChangeEditRemote)
72 ON_EN_CHANGE(IDC_EDIT_URL, &CSettingGitRemote::OnEnChangeEditUrl)
73 ON_EN_CHANGE(IDC_EDIT_PUSHURL, &CSettingGitRemote::OnEnChangeEditPushUrl)
74 ON_EN_CHANGE(IDC_EDIT_PUTTY_KEY, &CSettingGitRemote::OnEnChangeEditPuttyKey)
75 ON_CBN_SELCHANGE(IDC_COMBO_TAGOPT, &CSettingGitRemote::OnCbnSelchangeComboTagOpt)
76 ON_BN_CLICKED(IDC_CHECK_PRUNE, &CSettingGitRemote::OnBnClickedCheckprune)
77 ON_BN_CLICKED(IDC_CHECK_PRUNEALL, &CSettingGitRemote::OnBnClickedCheckpruneall)
78 ON_BN_CLICKED(IDC_CHECK_PUSHDEFAULT, &CSettingGitRemote::OnBnClickedCheckpushdefault)
79 ON_BN_CLICKED(IDC_BUTTON_REMOVE, &CSettingGitRemote::OnBnClickedButtonRemove)
80 ON_BN_CLICKED(IDC_BUTTON_RENAME_REMOTE, &CSettingGitRemote::OnBnClickedButtonRenameRemote)
81 END_MESSAGE_MAP()
83 static void ShowEditBalloon(HWND hDlg, UINT nIdControl, UINT nIdText, UINT nIdTitle, int nIcon = TTI_WARNING)
85 CString text(MAKEINTRESOURCE(nIdText));
86 CString title(MAKEINTRESOURCE(nIdTitle));
87 EDITBALLOONTIP bt;
88 bt.cbStruct = sizeof(bt);
89 bt.pszText = text;
90 bt.pszTitle = title;
91 bt.ttiIcon = nIcon;
92 SendDlgItemMessage(hDlg, nIdControl, EM_SHOWBALLOONTIP, 0, (LPARAM)&bt);
95 #define TIMER_PREFILL 1
97 BOOL CSettingGitRemote::OnInitDialog()
99 ISettingsPropPage::OnInitDialog();
101 AdjustControlSize(IDC_CHECK_PRUNE);
102 AdjustControlSize(IDC_CHECK_PRUNEALL);
103 AdjustControlSize(IDC_CHECK_PUSHDEFAULT);
105 STRING_VECTOR remotes;
106 g_Git.GetRemoteList(remotes);
107 m_ctrlRemoteList.ResetContent();
108 for (size_t i = 0; i < remotes.size(); i++)
109 m_ctrlRemoteList.AddString(remotes[i]);
111 m_ctrlTagOpt.AddString(CString(MAKEINTRESOURCE(IDS_FETCH_REACHABLE)));
112 m_ctrlTagOpt.AddString(CString(MAKEINTRESOURCE(IDS_NONE)));
113 m_ctrlTagOpt.AddString(CString(MAKEINTRESOURCE(CAppUtils::GetMsysgitVersion() < 0x01090000 ? IDS_FETCH_TAGS_ONLY : IDS_ALL)));
114 m_ctrlTagOpt.SetCurSel(0);
116 if (CAppUtils::GetMsysgitVersion() < 0x0108030)
118 GetDlgItem(IDC_CHECK_PUSHDEFAULT)->ShowWindow(SW_HIDE);
120 if (CAppUtils::GetMsysgitVersion() < 0x0108050)
122 GetDlgItem(IDC_CHECK_PRUNE)->ShowWindow(SW_HIDE);
123 GetDlgItem(IDC_CHECK_PRUNEALL)->ShowWindow(SW_HIDE);
126 CString pruneAll = g_Git.GetConfigValue(_T("fetch.prune"));
127 m_bPruneAll = pruneAll == _T("true") ? TRUE : FALSE;
129 //this->GetDlgItem(IDC_EDIT_REMOTE)->EnableWindow(FALSE);
130 this->UpdateData(FALSE);
132 SetTimer(TIMER_PREFILL, 1000, nullptr);
133 return TRUE;
135 // CSettingGitRemote message handlers
137 void CSettingGitRemote::OnTimer(UINT_PTR nIDEvent)
139 if (nIDEvent == TIMER_PREFILL)
141 if (m_strRemote.IsEmpty() && m_ctrlRemoteList.GetCount() == 0)
143 ShowEditBalloon(m_hWnd, IDC_EDIT_URL, IDS_B_T_PREFILL_ORIGIN, IDS_HINT, TTI_INFO);
146 KillTimer(TIMER_PREFILL);
150 void CSettingGitRemote::OnBnClickedButtonBrowse()
152 CFileDialog dlg(TRUE,NULL,
153 NULL,
154 OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
155 CString(MAKEINTRESOURCE(IDS_PUTTYKEYFILEFILTER)));
157 this->UpdateData();
158 INT_PTR ret = dlg.DoModal();
159 SetCurrentDirectory(g_Git.m_CurrentDir);
160 if (ret == IDOK)
162 this->m_strPuttyKeyfile = dlg.GetPathName();
163 this->UpdateData(FALSE);
164 OnEnChangeEditPuttyKey();
168 void CSettingGitRemote::OnBnClickedButtonAdd()
170 this->UpdateData();
172 if(m_strRemote.IsEmpty())
174 CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_REMOTEEMPTY, IDS_APPNAME, MB_OK | MB_ICONERROR);
175 return;
177 if(m_strUrl.IsEmpty())
179 CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_URLEMPTY, IDS_APPNAME, MB_OK | MB_ICONERROR);
180 return;
183 m_ChangedMask = REMOTE_NAME | REMOTE_URL | REMOTE_PUTTYKEY | REMOTE_TAGOPT | REMOTE_PRUNE | REMOTE_PRUNEALL | REMOTE_PUSHDEFAULT | REMOTE_PUSHURL;
184 if(IsRemoteExist(m_strRemote))
186 CString msg;
187 msg.Format(IDS_PROC_GITCONFIG_OVERWRITEREMOTE, (LPCTSTR)m_strRemote);
188 if(CMessageBox::Show(NULL, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION | MB_DEFBUTTON2) == IDYES)
190 m_ChangedMask &= ~REMOTE_NAME;
192 else
193 return;
196 this->OnApply();
199 BOOL CSettingGitRemote::IsRemoteExist(CString &remote)
201 CString str;
202 for(int i=0;i<m_ctrlRemoteList.GetCount();i++)
204 m_ctrlRemoteList.GetText(i,str);
205 if(str == remote)
207 return true;
210 return false;
213 struct CheckRefspecStruct
215 CStringA remote;
216 bool result;
219 static int CheckRemoteCollideWithRefspec(const git_config_entry *entry, void * payload)
221 auto crs = (CheckRefspecStruct *)payload;
222 crs->result = false;
223 if (entry->name == "remote." + crs->remote + ".fetch")
224 return 0;
225 CStringA value = CStringA(entry->value);
226 CStringA match = ":refs/remotes/" + crs->remote;
227 int pos = value.Find(match);
228 if (pos < 0)
229 return 0;
230 if ((pos + match.GetLength() == value.GetLength()) || (value[pos + match.GetLength()] == '/'))
232 crs->result = true;
233 return GIT_EUSER;
235 return 0;
238 bool CSettingGitRemote::IsRemoteCollideWithRefspec(CString remote)
240 CheckRefspecStruct crs = { CUnicodeUtils::GetUTF8(remote), false };
241 CAutoConfig config(true);
242 git_config_add_file_ondisk(config, CGit::GetGitPathStringA(g_Git.GetGitLocalConfig()), GIT_CONFIG_LEVEL_LOCAL, FALSE);
243 char *patterns[] = { "remote\\..*\\.fetch", "svn-remote\\..*\\.fetch", "svn-remote\\..*\\.branches", "svn-remote\\..*\\.tags" };
244 for (auto pattern : patterns)
246 git_config_foreach_match(config, pattern, CheckRemoteCollideWithRefspec, &crs);
247 if (crs.result)
248 return true;
250 return false;
253 void CSettingGitRemote::OnLbnSelchangeListRemote()
255 CWaitCursor wait;
257 if(m_ChangedMask)
259 if(CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_SAVEREMOTE, IDS_APPNAME, 1, IDI_QUESTION, IDS_SAVEBUTTON, IDS_DISCARDBUTTON) == 1)
260 OnApply();
262 SetModified(FALSE);
264 CString cmd,output;
265 int index;
266 index = this->m_ctrlRemoteList.GetCurSel();
267 if(index<0)
269 m_strUrl.Empty();
270 m_strPushUrl.Empty();
271 m_strRemote.Empty();
272 m_strPuttyKeyfile.Empty();
273 this->UpdateData(FALSE);
274 return;
276 CString remote;
277 m_ctrlRemoteList.GetText(index,remote);
278 this->m_strRemote=remote;
280 cmd.Format(_T("remote.%s.url"), (LPCTSTR)remote);
281 m_strUrl.Empty();
282 m_strUrl = g_Git.GetConfigValue(cmd);
284 cmd.Format(_T("remote.%s.pushurl"), (LPCTSTR)remote);
285 m_strPushUrl.Empty();
286 m_strPushUrl = g_Git.GetConfigValue(cmd);
288 cmd.Format(_T("remote.%s.puttykeyfile"), (LPCTSTR)remote);
290 this->m_strPuttyKeyfile = g_Git.GetConfigValue(cmd);
292 m_ChangedMask=0;
295 cmd.Format(_T("remote.%s.tagopt"), (LPCTSTR)remote);
296 CString tagopt = g_Git.GetConfigValue(cmd);
297 index = 0;
298 if (tagopt == "--no-tags")
299 index = 1;
300 else if (tagopt == "--tags")
301 index = 2;
302 m_ctrlTagOpt.SetCurSel(index);
304 CString pushDefault = g_Git.GetConfigValue(_T("remote.pushdefault"));
305 m_bPushDefault = pushDefault == remote ? TRUE : FALSE;
306 cmd.Format(_T("remote.%s.prune"), (LPCTSTR)remote);
307 CString prune = g_Git.GetConfigValue(cmd);
308 m_bPrune = prune == _T("true") ? TRUE : prune == _T("false") ? FALSE : 2;
309 CString pruneAll = g_Git.GetConfigValue(_T("fetch.prune"));
310 m_bPruneAll = pruneAll == _T("true") ? TRUE : FALSE;
312 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);
313 GetDlgItem(IDC_BUTTON_REMOVE)->EnableWindow(TRUE);
314 GetDlgItem(IDC_BUTTON_RENAME_REMOTE)->EnableWindow(TRUE);
315 this->UpdateData(FALSE);
319 void CSettingGitRemote::OnEnChangeEditRemote()
321 m_ChangedMask|=REMOTE_NAME;
323 this->UpdateData();
325 if (IsRemoteCollideWithRefspec(m_strRemote))
326 ShowEditBalloon(m_hWnd, IDC_EDIT_REMOTE, IDS_B_T_REMOTE_NAME_COLLIDE, IDS_HINT, TTI_WARNING);
327 if( (!this->m_strRemote.IsEmpty())&&(!this->m_strUrl.IsEmpty()) )
328 this->SetModified();
331 void CSettingGitRemote::OnEnChangeEditUrl()
333 m_ChangedMask|=REMOTE_URL;
335 this->UpdateData();
337 if (m_strRemote.IsEmpty() && !m_strUrl.IsEmpty() && m_ctrlRemoteList.GetCount() == 0)
339 GetDlgItem(IDC_EDIT_REMOTE)->SetWindowText(_T("origin"));
340 OnEnChangeEditRemote();
343 if( (!this->m_strRemote.IsEmpty())&&(!this->m_strUrl.IsEmpty()) )
344 this->SetModified();
347 void CSettingGitRemote::OnEnChangeEditPushUrl()
349 m_ChangedMask |= REMOTE_PUSHURL;
351 this->UpdateData();
353 if (!this->m_strRemote.IsEmpty())
354 this->SetModified();
357 void CSettingGitRemote::OnEnChangeEditPuttyKey()
359 m_ChangedMask|=REMOTE_PUTTYKEY;
361 this->UpdateData();
362 if (!this->m_strUrl.IsEmpty())
363 this->SetModified();
366 void CSettingGitRemote::OnCbnSelchangeComboTagOpt()
368 m_ChangedMask |= REMOTE_TAGOPT;
370 this->UpdateData();
371 this->SetModified();
374 void CSettingGitRemote::OnBnClickedCheckprune()
376 m_ChangedMask |= REMOTE_PRUNE;
378 this->UpdateData();
379 this->SetModified();
382 void CSettingGitRemote::OnBnClickedCheckpruneall()
384 m_ChangedMask |= REMOTE_PRUNEALL;
385 UpdateData();
386 SetModified();
389 void CSettingGitRemote::OnBnClickedCheckpushdefault()
391 m_ChangedMask |= REMOTE_PUSHDEFAULT;
392 UpdateData();
393 SetModified();
396 BOOL CSettingGitRemote::Save(CString key,CString value)
398 CString cmd,out;
400 cmd.Format(_T("remote.%s.%s"), (LPCTSTR)m_strRemote, (LPCTSTR)key);
401 if (value.IsEmpty())
403 // don't check result code. it fails if the entry not exist
404 g_Git.UnsetConfigValue(cmd, CONFIG_LOCAL);
405 if (!g_Git.GetConfigValue(cmd).IsEmpty())
407 CString msg;
408 msg.Format(IDS_PROC_SAVECONFIGFAILED, (LPCTSTR)cmd, (LPCTSTR)value);
409 CMessageBox::Show(NULL, msg, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
410 return FALSE;
412 return TRUE;
415 if (g_Git.SetConfigValue(cmd, value, CONFIG_LOCAL))
417 CString msg;
418 msg.Format(IDS_PROC_SAVECONFIGFAILED, (LPCTSTR)cmd, (LPCTSTR)value);
419 CMessageBox::Show(NULL, msg, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
420 return FALSE;
422 return TRUE;
425 BOOL CSettingGitRemote::SaveGeneral(CString key, CString value)
427 if (value.IsEmpty())
429 // don't check result code. it fails if the entry not exist
430 g_Git.UnsetConfigValue(key, CONFIG_LOCAL);
431 if (!g_Git.GetConfigValue(key).IsEmpty())
433 CString msg;
434 msg.Format(IDS_PROC_SAVECONFIGFAILED, (LPCTSTR)key, (LPCTSTR)value);
435 CMessageBox::Show(NULL, msg, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
436 return FALSE;
438 return TRUE;
441 if (g_Git.SetConfigValue(key, value, CONFIG_LOCAL))
443 CString msg;
444 msg.Format(IDS_PROC_SAVECONFIGFAILED, (LPCTSTR)key, (LPCTSTR)value);
445 CMessageBox::Show(NULL, msg, _T("TortoiseGit"), MB_OK | MB_ICONERROR);
446 return FALSE;
449 return TRUE;
452 BOOL CSettingGitRemote::OnApply()
454 CWaitCursor wait;
455 this->UpdateData();
457 if (m_ChangedMask & REMOTE_PUSHDEFAULT)
459 if (!m_strRemote.Trim().IsEmpty() && m_bPushDefault)
461 if (!SaveGeneral(_T("remote.pushdefault"), m_strRemote.Trim()))
462 return FALSE;
464 if (!m_bPushDefault)
466 if (!SaveGeneral(_T("remote.pushdefault"), _T("")))
467 return FALSE;
470 m_ChangedMask &= ~REMOTE_PUSHDEFAULT;
473 if (m_ChangedMask & REMOTE_PRUNEALL)
475 if (!SaveGeneral(_T("fetch.prune"), m_bPruneAll == TRUE ? _T("true") : _T("")))
476 return FALSE;
477 m_ChangedMask &= ~REMOTE_PRUNEALL;
480 if (m_ChangedMask && m_strRemote.Trim().IsEmpty())
482 CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_REMOTEEMPTY, IDS_APPNAME, MB_OK | MB_ICONERROR);
483 return FALSE;
486 if(m_ChangedMask & REMOTE_NAME)
488 //Add Remote
489 if(m_strRemote.IsEmpty())
491 CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_REMOTEEMPTY, IDS_APPNAME, MB_OK | MB_ICONERROR);
492 return FALSE;
494 if(m_strUrl.IsEmpty())
496 CMessageBox::Show(NULL, IDS_PROC_GITCONFIG_URLEMPTY, IDS_APPNAME, MB_OK | MB_ICONERROR);
497 return FALSE;
500 if (m_ctrlRemoteList.GetCount() > 0)
502 // tagopt not --no-tags
503 if (m_ctrlTagOpt.GetCurSel() != 1)
505 if (CMessageBox::ShowCheck(GetSafeHwnd(), IDS_PROC_GITCONFIG_ASKTAGOPT, IDS_APPNAME, MB_YESNO | MB_ICONQUESTION, _T("TagOptNoTagsWarning"), IDS_MSGBOX_DONOTSHOWAGAIN) == IDYES)
507 m_ctrlTagOpt.SetCurSel(1);
508 m_ChangedMask |= REMOTE_TAGOPT;
513 m_strUrl.Replace(L'\\', L'/');
514 CString cmd,out;
515 cmd.Format(_T("git.exe remote add \"%s\" \"%s\""), (LPCTSTR)m_strRemote, (LPCTSTR)m_strUrl);
516 if (g_Git.Run(cmd, &out, CP_UTF8))
518 CMessageBox::Show(NULL,out,_T("TorotiseGit"),MB_OK|MB_ICONERROR);
519 return FALSE;
521 m_ChangedMask &= ~REMOTE_URL;
523 m_ctrlRemoteList.SetCurSel(m_ctrlRemoteList.AddString(m_strRemote));
524 GetDlgItem(IDC_BUTTON_ADD)->EnableWindow(TRUE);
525 GetDlgItem(IDC_BUTTON_RENAME_REMOTE)->EnableWindow(TRUE);
526 if (!m_bNoFetch && CMessageBox::Show(NULL, IDS_SETTINGS_FETCH_ADDEDREMOTE, IDS_APPNAME, MB_ICONQUESTION | MB_YESNO) == IDYES)
527 CCommonAppUtils::RunTortoiseGitProc(_T("/command:fetch /path:\"") + g_Git.m_CurrentDir + _T("\" /remote:\"") + m_strRemote + _T("\""));
529 if(m_ChangedMask & REMOTE_URL)
531 m_strUrl.Replace(L'\\', L'/');
532 if (!Save(_T("url"),this->m_strUrl))
533 return FALSE;
536 if(m_ChangedMask & REMOTE_PUTTYKEY)
538 if (!Save(_T("puttykeyfile"),this->m_strPuttyKeyfile))
539 return FALSE;
542 if (m_ChangedMask & REMOTE_TAGOPT)
544 CString tagopt;
545 int index = m_ctrlTagOpt.GetCurSel();
546 if (index == 1)
547 tagopt = "--no-tags";
548 else if (index == 2)
549 tagopt = "--tags";
550 if (!Save(_T("tagopt"), tagopt))
551 return FALSE;
554 if (m_ChangedMask & REMOTE_PRUNE)
556 if (!Save(_T("prune"), m_bPrune == TRUE ? _T("true") : m_bPrune == FALSE ? _T("false") : _T("")))
557 return FALSE;
560 if (m_ChangedMask & REMOTE_PUSHURL)
562 m_strPushUrl.Replace(L'\\', L'/');
563 if (!Save(_T("pushurl"), m_strPushUrl))
564 return FALSE;
567 SetModified(FALSE);
569 m_ChangedMask = 0;
570 return ISettingsPropPage::OnApply();
573 void CleanupSyncRemotes(const CString& remote)
575 CString workingDir = g_Git.m_CurrentDir;
576 workingDir.Replace(_T(':'), _T('_'));
577 CHistoryCombo::RemoveEntryFromHistory(_T("Software\\TortoiseGit\\History\\SyncURL\\") + workingDir, _T("url"), remote);
580 void CSettingGitRemote::OnBnClickedButtonRemove()
582 int index;
583 index=m_ctrlRemoteList.GetCurSel();
584 if(index>=0)
586 CString str;
587 m_ctrlRemoteList.GetText(index,str);
588 CString msg;
589 msg.Format(IDS_WARN_REMOVE, (LPCTSTR)str);
590 if(CMessageBox::Show(NULL, msg, _T("TortoiseGit"), MB_YESNO | MB_ICONQUESTION) == IDYES)
592 CString cmd,out;
593 cmd.Format(_T("git.exe remote rm %s"), (LPCTSTR)str);
594 if (g_Git.Run(cmd, &out, CP_UTF8))
596 CMessageBox::Show(NULL, out,_T("TortoiseGit"),MB_OK|MB_ICONERROR);
597 return;
600 CleanupSyncRemotes(str);
601 m_ctrlRemoteList.DeleteString(index);
602 OnLbnSelchangeListRemote();
607 void CSettingGitRemote::OnBnClickedButtonRenameRemote()
609 int sel = m_ctrlRemoteList.GetCurSel();
610 if (sel >= 0)
612 CString oldRemote, newRemote;
613 m_ctrlRemoteList.GetText(sel, oldRemote);
614 GetDlgItem(IDC_EDIT_REMOTE)->GetWindowText(newRemote);
615 CString cmd, out;
616 cmd.Format(_T("git.exe remote rename %s %s"), (LPCTSTR)oldRemote, (LPCTSTR)newRemote);
617 if (g_Git.Run(cmd, &out, CP_UTF8))
619 CMessageBox::Show(NULL, out,_T("TortoiseGit"), MB_OK | MB_ICONERROR);
620 return;
623 CleanupSyncRemotes(oldRemote);
624 m_ctrlRemoteList.DeleteString(sel);
625 m_ctrlRemoteList.SetCurSel(m_ctrlRemoteList.AddString(newRemote));
626 m_ChangedMask &= ~REMOTE_NAME;
627 if (!m_ChangedMask)
628 this->SetModified(FALSE);