make bisect work (initial commit)
[TortoiseGit.git] / src / TortoiseProc / Commands / DropMoveCommand.cpp
blob6307fd281fa111abca94bfce708b95197b51e023
1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008 - TortoiseSVN
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 "DropMoveCommand.h"
22 #include "SysProgressDlg.h"
23 #include "MessageBox.h"
24 #include "Git.h"
25 #include "RenameDlg.h"
26 #include "ShellUpdater.h"
27 #include "commonresource.h"
29 bool DropMoveCommand::Execute()
31 CString droppath = parser.GetVal(_T("droptarget"));
32 CString ProjectTop;
33 if (!CTGitPath(droppath).HasAdminDir(&ProjectTop))
34 return FALSE;
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);
39 return FALSE;
42 droppath = droppath.Right(droppath.GetLength()-ProjectTop.GetLength()-1);
44 unsigned long count = 0;
45 pathList.RemoveAdminPaths();
46 CString sNewName;
48 if ((parser.HasKey(_T("rename")))&&(pathList.GetCount()==1))
50 // ask for a new name of the source item
51 do
53 CRenameDlg renDlg;
54 renDlg.m_windowtitle.LoadString(IDS_PROC_MOVERENAME);
55 renDlg.m_name = pathList[0].GetFileOrDirectoryName();
56 if (renDlg.DoModal() != IDOK)
58 return FALSE;
60 sNewName = renDlg.m_name;
61 } while(sNewName.IsEmpty() || PathFileExists(droppath+_T("\\")+sNewName));
63 CSysProgressDlg progress;
64 if (progress.IsValid())
66 progress.SetTitle(IDS_PROC_MOVING);
67 progress.SetAnimation(IDR_MOVEANI);
68 progress.SetTime(true);
69 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));
71 for(int nPath = 0; nPath < pathList.GetCount(); nPath++)
73 CTGitPath destPath;
74 if (sNewName.IsEmpty())
75 destPath = CTGitPath(droppath+_T("\\")+pathList[nPath].GetFileOrDirectoryName());
76 else
77 destPath = CTGitPath(droppath+_T("\\")+sNewName);
78 if (destPath.Exists())
80 CString name = pathList[nPath].GetFileOrDirectoryName();
81 if (!sNewName.IsEmpty())
82 name = sNewName;
83 progress.Stop();
84 CRenameDlg dlg;
85 dlg.m_name = name;
86 dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);
87 if (dlg.DoModal() != IDOK)
89 return FALSE;
91 destPath.SetFromWin(droppath+_T("\\")+dlg.m_name);
93 CString cmd,out;
95 cmd.Format(_T("git.exe mv -- \"%s\" \"%s\""),pathList[nPath].GetGitPathString(),destPath.GetGitPathString());
96 if(g_Git.Run(cmd,&out,CP_ACP))
98 if (CMessageBox::Show(hwndExplorer, out, _T("TortoiseGit"), MB_YESNO)==IDYES)
100 #if 0
101 if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, TRUE))
103 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);
104 return FALSE; //get out of here
106 CShellUpdater::Instance().AddPathForUpdate(destPath);
107 #endif
109 else
111 //TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());
112 CMessageBox::Show(hwndExplorer, _T("Cancel"), _T("TortoiseGit"), MB_ICONERROR);
113 return FALSE; //get out of here
116 else
117 CShellUpdater::Instance().AddPathForUpdate(destPath);
118 count++;
119 if (progress.IsValid())
121 progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, pathList[nPath].GetWinPath());
122 progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());
123 progress.SetProgress(count, pathList.GetCount());
125 if ((progress.IsValid())&&(progress.HasUserCancelled()))
127 CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);
128 return FALSE;
131 return true;