Make sure a separator is added after Stash menu items
[TortoiseGit.git] / src / TortoiseProc / Commands / RenameCommand.cpp
blob6b1bdee2a430c03d66f6dccf5cf506ff020362b1
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012, 2015 - TortoiseGit
4 // Copyright (C) 2007-2008 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "RenameCommand.h"
23 #include "MessageBox.h"
24 #include "RenameDlg.h"
25 #include "Git.h"
26 #include "ShellUpdater.h"
28 bool RenameCommand::Execute()
30 bool bRet = true;
31 CString filename = cmdLinePath.GetFileOrDirectoryName();
32 CString basePath = cmdLinePath.GetContainingDirectory().GetGitPathString();
34 // show the rename dialog until the user either cancels or enters a new
35 // name (one that's different to the original name
36 CString sNewName;
39 CRenameDlg dlg;
40 dlg.m_name = filename;
41 if (dlg.DoModal() != IDOK)
42 return FALSE;
43 sNewName = dlg.m_name;
44 } while(PathIsRelative(sNewName) && !PathIsURL(sNewName) && (sNewName.IsEmpty() || (sNewName.Compare(filename)==0)));
46 if(!basePath.IsEmpty())
47 sNewName=basePath+"/"+sNewName;
49 CString force;
50 // if the filenames only differ in case, we have to pass "-f"
51 if (sNewName.CompareNoCase(cmdLinePath.GetGitPathString()) == 0)
52 force = _T("-f ");
54 CString cmd;
55 CString output;
56 cmd.Format(_T("git.exe mv %s-- \"%s\" \"%s\""),
57 (LPCTSTR)force,
58 (LPCTSTR)cmdLinePath.GetGitPathString(),
59 (LPCTSTR)sNewName);
61 if (g_Git.Run(cmd, &output, CP_UTF8))
63 CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_OK);
64 bRet = false;
67 CTGitPath newpath;
68 newpath.SetFromGit(sNewName);
70 CShellUpdater::Instance().AddPathForUpdate(newpath);
71 CShellUpdater::Instance().Flush();
72 return bRet;