1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009,2011-2014 - 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 "DropMoveCommand.h"
23 #include "SysProgressDlg.h"
24 #include "MessageBox.h"
26 #include "RenameDlg.h"
27 #include "ShellUpdater.h"
29 bool DropMoveCommand::Execute()
31 CString droppath
= parser
.GetVal(_T("droptarget"));
33 if (!CTGitPath(droppath
).HasAdminDir(&ProjectTop
))
36 if (ProjectTop
!= g_Git
.m_CurrentDir
)
38 CMessageBox::Show(NULL
,_T("Target and source must be the same git repository"),_T("TortoiseGit"),MB_OK
);
42 if (ProjectTop
.GetLength() == 3 && ProjectTop
.Mid(1, 2) == _T(":\\")) // working tree root is directly on a drive
43 droppath
= droppath
.Right(droppath
.GetLength() - ProjectTop
.GetLength());
45 droppath
= droppath
.Right(droppath
.GetLength() - ProjectTop
.GetLength() - 1);
46 if (!droppath
.IsEmpty())
49 unsigned long count
= 0;
50 pathList
.RemoveAdminPaths();
53 if ((parser
.HasKey(_T("rename")))&&(pathList
.GetCount()==1))
55 // ask for a new name of the source item
59 renDlg
.m_windowtitle
.LoadString(IDS_PROC_MOVERENAME
);
60 renDlg
.m_name
= pathList
[0].GetFileOrDirectoryName();
61 if (renDlg
.DoModal() != IDOK
)
65 sNewName
= renDlg
.m_name
;
66 } while(sNewName
.IsEmpty() || PathFileExists(droppath
+ sNewName
));
68 CSysProgressDlg progress
;
69 if (progress
.IsValid())
71 progress
.SetTitle(IDS_PROC_MOVING
);
72 progress
.SetAnimation(IDR_MOVEANI
);
73 progress
.SetTime(true);
74 progress
.ShowModeless(CWnd::FromHandle(hwndExplorer
));
76 for (int nPath
= 0; nPath
< pathList
.GetCount(); ++nPath
)
79 if (sNewName
.IsEmpty())
80 destPath
= CTGitPath(droppath
+ pathList
[nPath
].GetFileOrDirectoryName());
82 destPath
= CTGitPath(droppath
+ sNewName
);
83 if (destPath
.Exists())
85 CString name
= pathList
[nPath
].GetFileOrDirectoryName();
86 if (!sNewName
.IsEmpty())
91 dlg
.m_windowtitle
.Format(IDS_PROC_NEWNAMEMOVE
, (LPCTSTR
)name
);
92 if (dlg
.DoModal() != IDOK
)
96 destPath
.SetFromWin(droppath
+ dlg
.m_name
);
100 cmd
.Format(_T("git.exe mv -- \"%s\" \"%s\""),pathList
[nPath
].GetGitPathString(),destPath
.GetGitPathString());
101 if (g_Git
.Run(cmd
, &out
, CP_UTF8
))
103 if (CMessageBox::Show(hwndExplorer
, out
, _T("TortoiseGit"), 2, IDI_EXCLAMATION
, CString(MAKEINTRESOURCE(IDS_IGNOREBUTTON
)), CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
))) == 1)
106 if (!svn
.Move(CTSVNPathList(pathList
[nPath
]), destPath
, TRUE
))
108 CMessageBox::Show(hwndExplorer
, svn
.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR
);
109 return FALSE
; //get out of here
111 CShellUpdater::Instance().AddPathForUpdate(destPath
);
116 CMessageBox::Show(hwndExplorer
, IDS_USERCANCELLED
, IDS_APPNAME
, MB_ICONERROR
);
117 return FALSE
; //get out of here
121 CShellUpdater::Instance().AddPathForUpdate(destPath
);
123 if (progress
.IsValid())
125 progress
.FormatPathLine(1, IDS_PROC_MOVINGPROG
, pathList
[nPath
].GetWinPath());
126 progress
.FormatPathLine(2, IDS_PROC_CPYMVPROG2
, destPath
.GetWinPath());
127 progress
.SetProgress(count
, pathList
.GetCount());
129 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
131 CMessageBox::Show(hwndExplorer
, IDS_USERCANCELLED
, IDS_APPNAME
, MB_ICONINFORMATION
);