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