Make tag date readable
[TortoiseGit.git] / src / TortoiseProc / Commands / RenameCommand.cpp
blob14d20c9bd8a46bf102654acf96dde835fefdd75c
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.
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;
37 CRenameDlg dlg;
38 dlg.SetInputValidator([&](const int /*nID*/, const CString& input) -> CString
40 CString newName;
41 if (!basePath.IsEmpty())
42 newName = basePath + "/" + input;
43 else
44 newName = input;
46 if (newName.CompareNoCase(cmdLinePath.GetGitPathString()) != 0 && PathFileExists(g_Git.CombinePath(newName)))
47 return CString(CFormatMessageWrapper(ERROR_FILE_EXISTS));
49 return{};
50 });
51 dlg.m_sBaseDir = g_Git.CombinePath(basePath);
52 dlg.m_name = filename;
53 if (dlg.DoModal() != IDOK)
54 return FALSE;
55 if (!basePath.IsEmpty())
56 sNewName = basePath + "/" + dlg.m_name;
57 else
58 sNewName = dlg.m_name;
60 CString force;
61 // if the filenames only differ in case, we have to pass "-f"
62 if (sNewName.CompareNoCase(cmdLinePath.GetGitPathString()) == 0)
63 force = L"-f ";
65 CString cmd;
66 CString output;
67 cmd.Format(L"git.exe mv %s-- \"%s\" \"%s\"",
68 (LPCTSTR)force,
69 (LPCTSTR)cmdLinePath.GetGitPathString(),
70 (LPCTSTR)sNewName);
72 if (g_Git.Run(cmd, &output, CP_UTF8))
74 CMessageBox::Show(hwndExplorer, output, L"TortoiseGit", MB_OK);
75 bRet = false;
78 CTGitPath newpath;
79 newpath.SetFromGit(sNewName);
81 CShellUpdater::Instance().AddPathForUpdate(newpath);
82 CShellUpdater::Instance().Flush();
83 return bRet;