1 // TortoiseGit - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2008 - TortoiseGit
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "PasteMoveCommand.h"
\r
22 #include "SysProgressDlg.h"
\r
23 #include "MessageBox.h"
\r
25 #include "GitStatus.h"
\r
26 #include "RenameDlg.h"
\r
27 #include "ShellUpdater.h"
\r
28 #include "ProjectProperties.h"
\r
29 #include "CommonResource.h"
\r
31 bool PasteMoveCommand::Execute()
\r
33 CString sDroppath = parser.GetVal(_T("droptarget"));
\r
34 CTGitPath dropPath(sDroppath);
\r
35 ProjectProperties props;
\r
36 props.ReadProps(dropPath);
\r
37 if (dropPath.IsAdminDir())
\r
40 if(!dropPath.HasAdminDir(&g_Git.m_CurrentDir))
\r
44 unsigned long count = 0;
\r
45 orgPathList.RemoveAdminPaths();
\r
47 CSysProgressDlg progress;
\r
48 progress.SetTitle(IDS_PROC_MOVING);
\r
49 progress.SetAnimation(IDR_MOVEANI);
\r
50 progress.SetTime(true);
\r
51 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
\r
52 for(int nPath = 0; nPath < orgPathList.GetCount(); nPath++)
\r
55 if (sNewName.IsEmpty())
\r
56 destPath = CTGitPath(sDroppath+_T("\\")+orgPathList[nPath].GetFileOrDirectoryName());
\r
58 destPath = CTGitPath(sDroppath+_T("\\")+sNewName);
\r
59 if (destPath.Exists())
\r
61 CString name = orgPathList[nPath].GetFileOrDirectoryName();
\r
62 if (!sNewName.IsEmpty())
\r
67 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);
\r
68 if (dlg.DoModal() != IDOK)
\r
72 destPath.SetFromWin(sDroppath+_T("\\")+dlg.m_name);
\r
76 orgPathList[nPath].HasAdminDir(&top);
\r
77 git_wc_status_kind s = status.GetAllStatus(orgPathList[nPath]);
\r
78 if ((s == git_wc_status_none)||(s == git_wc_status_unversioned)||(s == git_wc_status_ignored)||top != g_Git.m_CurrentDir)
\r
80 // source file is unversioned: move the file to the target, then add it
\r
81 MoveFile(orgPathList[nPath].GetWinPath(), destPath.GetWinPath());
\r
83 cmd.Format(_T("git.exe add \"%s\""),destPath.GetWinPath());
\r
84 if(g_Git.Run(cmd,&output,CP_ACP))
\r
85 //if (!Git.Add(CTGitorgPathList(destPath), &props, Git_depth_infinity, true, false, true))
\r
87 TRACE(_T("%s\n"), output);
\r
88 CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);
\r
89 return FALSE; //get out of here
\r
91 CShellUpdater::Instance().AddPathForUpdate(destPath);
\r
96 cmd.Format(_T("git.exe mv \"%s\" \"%s\""),orgPathList[nPath].GetGitPathString(),destPath.GetGitPathString());
\r
97 if(g_Git.Run(cmd,&output,CP_ACP))
\r
98 //if (!Git.Move(CTGitorgPathList(orgPathList[nPath]), destPath, FALSE))
\r
101 if (Git.Err && (Git.Err->apr_err == Git_ERR_UNVERSIONED_RESOURCE ||
\r
102 Git.Err->apr_err == Git_ERR_CLIENT_MODIFIED))
\r
104 // file/folder seems to have local modifications. Ask the user if
\r
105 // a force is requested.
\r
106 CString temp = Git.GetLastErrorMessage();
\r
107 CString sQuestion(MAKEINTRESOURCE(IDS_PROC_FORCEMOVE));
\r
108 temp += _T("\n") + sQuestion;
\r
109 if (CMessageBox::Show(hwndExplorer, temp, _T("TortoiseGit"), MB_YESNO)==IDYES)
\r
111 if (!Git.Move(CTGitPathList(pathList[nPath]), destPath, TRUE))
\r
113 CMessageBox::Show(hwndExplorer, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
\r
114 return FALSE; //get out of here
\r
116 CShellUpdater::Instance().AddPathForUpdate(destPath);
\r
122 TRACE(_T("%s\n"), (LPCTSTR)output);
\r
123 CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);
\r
124 return FALSE; //get out of here
\r
128 CShellUpdater::Instance().AddPathForUpdate(destPath);
\r
131 if (progress.IsValid())
\r
133 progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, orgPathList[nPath].GetWinPath());
\r
134 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());
\r
135 progress.SetProgress(count, orgPathList.GetCount());
\r
137 if ((progress.IsValid())&&(progress.HasUserCancelled()))
\r
139 CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
\r