Replace var++ by ++var and use size_t where necessary
[TortoiseGit.git] / src / TortoiseProc / Commands / PasteMoveCommand.cpp
blobb428e6c995ed9a8345822e2a4b9685551138a468
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"
28 #include "ProjectProperties.h"
30 bool PasteMoveCommand::Execute()
32 CString sDroppath = parser.GetVal(_T("droptarget"));
33 CTGitPath dropPath(sDroppath);
34 ProjectProperties props;
35 props.ReadProps(dropPath);
36 if (dropPath.IsAdminDir())
37 return FALSE;
39 if(!dropPath.HasAdminDir(&g_Git.m_CurrentDir))
40 return FALSE;
42 GitStatus status;
43 unsigned long count = 0;
44 orgPathList.RemoveAdminPaths();
45 CString sNewName;
46 CSysProgressDlg progress;
47 progress.SetTitle(IDS_PROC_MOVING);
48 progress.SetAnimation(IDR_MOVEANI);
49 progress.SetTime(true);
50 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
51 for (int nPath = 0; nPath < orgPathList.GetCount(); ++nPath)
53 CTGitPath destPath;
54 if (sNewName.IsEmpty())
55 destPath = CTGitPath(sDroppath+_T("\\")+orgPathList[nPath].GetFileOrDirectoryName());
56 else
57 destPath = CTGitPath(sDroppath+_T("\\")+sNewName);
58 if (destPath.Exists())
60 CString name = orgPathList[nPath].GetFileOrDirectoryName();
61 if (!sNewName.IsEmpty())
62 name = sNewName;
63 progress.Stop();
64 CRenameDlg dlg;
65 dlg.m_name = name;
66 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);
67 if (dlg.DoModal() != IDOK)
69 return FALSE;
71 destPath.SetFromWin(sDroppath+_T("\\")+dlg.m_name);
73 CString top;
74 top.Empty();
75 orgPathList[nPath].HasAdminDir(&top);
76 git_wc_status_kind s = status.GetAllStatus(orgPathList[nPath]);
77 if ((s == git_wc_status_none)||(s == git_wc_status_unversioned)||(s == git_wc_status_ignored)||top != g_Git.m_CurrentDir)
79 // source file is unversioned: move the file to the target, then add it
80 MoveFile(orgPathList[nPath].GetWinPath(), destPath.GetWinPath());
81 CString cmd,output;
82 cmd.Format(_T("git.exe add \"%s\""),destPath.GetWinPath());
83 if (g_Git.Run(cmd, &output, CP_UTF8))
84 //if (!Git.Add(CTGitorgPathList(destPath), &props, Git_depth_infinity, true, false, true))
86 TRACE(_T("%s\n"), output);
87 CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);
88 return FALSE; //get out of here
90 CShellUpdater::Instance().AddPathForUpdate(destPath);
92 else
94 CString cmd,output;
95 cmd.Format(_T("git.exe mv \"%s\" \"%s\""),orgPathList[nPath].GetGitPathString(),destPath.GetGitPathString());
96 if (g_Git.Run(cmd, &output, CP_UTF8))
97 //if (!Git.Move(CTGitorgPathList(orgPathList[nPath]), destPath, FALSE))
99 #if 0
100 if (Git.Err && (Git.Err->apr_err == Git_ERR_UNVERSIONED_RESOURCE ||
101 Git.Err->apr_err == Git_ERR_CLIENT_MODIFIED))
103 // file/folder seems to have local modifications. Ask the user if
104 // a force is requested.
105 CString temp = Git.GetLastErrorMessage();
106 CString sQuestion(MAKEINTRESOURCE(IDS_PROC_FORCEMOVE));
107 temp += _T("\n") + sQuestion;
108 if (CMessageBox::Show(hwndExplorer, temp, _T("TortoiseGit"), MB_YESNO)==IDYES)
110 if (!Git.Move(CTGitPathList(pathList[nPath]), destPath, TRUE))
112 CMessageBox::Show(hwndExplorer, Git.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
113 return FALSE; //get out of here
115 CShellUpdater::Instance().AddPathForUpdate(destPath);
118 else
119 #endif
121 TRACE(_T("%s\n"), (LPCTSTR)output);
122 CMessageBox::Show(hwndExplorer, output, _T("TortoiseGit"), MB_ICONERROR);
123 return FALSE; //get out of here
126 else
127 CShellUpdater::Instance().AddPathForUpdate(destPath);
129 ++count;
130 if (progress.IsValid())
132 progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, orgPathList[nPath].GetWinPath());
133 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());
134 progress.SetProgress(count, orgPathList.GetCount());
136 if ((progress.IsValid())&&(progress.HasUserCancelled()))
138 CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
139 return FALSE;
142 return true;