1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008-2012, 2015-2017 - 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.
21 #include "RenameCommand.h"
23 #include "MessageBox.h"
24 #include "RenameDlg.h"
26 #include "ShellUpdater.h"
28 bool RenameCommand::Execute()
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
38 dlg
.SetInputValidator([&](const int /*nID*/, const CString
& input
) -> CString
41 if (!basePath
.IsEmpty())
42 newName
= basePath
+ "/" + input
;
46 if (newName
.CompareNoCase(cmdLinePath
.GetGitPathString()) != 0 && PathFileExists(g_Git
.CombinePath(newName
)))
47 return CString(CFormatMessageWrapper(ERROR_FILE_EXISTS
));
51 dlg
.m_sBaseDir
= g_Git
.CombinePath(basePath
);
52 dlg
.m_name
= filename
;
53 if (dlg
.DoModal() != IDOK
)
55 if (!basePath
.IsEmpty())
56 sNewName
= basePath
+ "/" + dlg
.m_name
;
58 sNewName
= dlg
.m_name
;
61 // if the filenames only differ in case, we have to pass "-f"
62 if (sNewName
.CompareNoCase(cmdLinePath
.GetGitPathString()) == 0)
67 cmd
.Format(L
"git.exe mv %s-- \"%s\" \"%s\"",
69 (LPCTSTR
)cmdLinePath
.GetGitPathString(),
72 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
74 CMessageBox::Show(hwndExplorer
, output
, L
"TortoiseGit", MB_OK
);
79 newpath
.SetFromGit(sNewName
);
81 CShellUpdater::Instance().AddPathForUpdate(newpath
);
82 CShellUpdater::Instance().Flush();