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.
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
40 dlg
.m_name
= filename
;
41 if (dlg
.DoModal() != IDOK
)
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
;
50 // if the filenames only differ in case, we have to pass "-f"
51 if (sNewName
.CompareNoCase(cmdLinePath
.GetGitPathString()) == 0)
56 cmd
.Format(_T("git.exe mv %s-- \"%s\" \"%s\""),
58 (LPCTSTR
)cmdLinePath
.GetGitPathString(),
61 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
63 CMessageBox::Show(hwndExplorer
, output
, _T("TortoiseGit"), MB_OK
);
68 newpath
.SetFromGit(sNewName
);
70 CShellUpdater::Instance().AddPathForUpdate(newpath
);
71 CShellUpdater::Instance().Flush();