OSDN Git Service

Fixed issue #155: Fix SVN Rebase sets upstream as remotes/trunk
[tortoisegit/TortoiseGitJp.git] / src / TortoiseProc / Commands / DropMoveCommand.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2007-2008 - TortoiseSVN\r
4 \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
9 \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
14 \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
18 //\r
19 #include "StdAfx.h"\r
20 #include "DropMoveCommand.h"\r
21 \r
22 #include "SysProgressDlg.h"\r
23 #include "MessageBox.h"\r
24 #include "Git.h"\r
25 #include "RenameDlg.h"\r
26 #include "ShellUpdater.h"\r
27 #include "commonresource.h"\r
28 \r
29 bool DropMoveCommand::Execute()\r
30 {\r
31         CString droppath = parser.GetVal(_T("droptarget"));\r
32         CString ProjectTop;\r
33         if (CTGitPath(droppath).HasAdminDir(&ProjectTop))\r
34                 return FALSE;\r
35         \r
36         if (ProjectTop != g_Git.m_CurrentDir )\r
37         {\r
38                 CMessageBox::Show(NULL,_T("Target and source must be the same git repository"),_T("TortoiseGit"),MB_OK);\r
39                 return FALSE;\r
40         }\r
41 \r
42         droppath.Right(droppath.GetLength()-ProjectTop.GetLength()-1);\r
43 \r
44         unsigned long count = 0;\r
45         pathList.RemoveAdminPaths();\r
46         CString sNewName;\r
47 \r
48         if ((parser.HasKey(_T("rename")))&&(pathList.GetCount()==1))\r
49         {\r
50                 // ask for a new name of the source item\r
51                 do \r
52                 {\r
53                         CRenameDlg renDlg;\r
54                         renDlg.m_windowtitle.LoadString(IDS_PROC_MOVERENAME);\r
55                         renDlg.m_name = pathList[0].GetFileOrDirectoryName();\r
56                         if (renDlg.DoModal() != IDOK)\r
57                         {\r
58                                 return FALSE;\r
59                         }\r
60                         sNewName = renDlg.m_name;\r
61                 } while(sNewName.IsEmpty() || PathFileExists(droppath+_T("\\")+sNewName));\r
62         }\r
63         CSysProgressDlg progress;\r
64         if (progress.IsValid())\r
65         {\r
66                 progress.SetTitle(IDS_PROC_MOVING);\r
67                 progress.SetAnimation(IDR_MOVEANI);\r
68                 progress.SetTime(true);\r
69                 progress.ShowModeless(CWnd::FromHandle(hwndExplorer));\r
70         }\r
71         for(int nPath = 0; nPath < pathList.GetCount(); nPath++)\r
72         {\r
73                 CTGitPath destPath;\r
74                 if (sNewName.IsEmpty())\r
75                         destPath = CTGitPath(droppath+_T("\\")+pathList[nPath].GetFileOrDirectoryName());\r
76                 else\r
77                         destPath = CTGitPath(droppath+_T("\\")+sNewName);\r
78                 if (destPath.Exists())\r
79                 {\r
80                         CString name = pathList[nPath].GetFileOrDirectoryName();\r
81                         if (!sNewName.IsEmpty())\r
82                                 name = sNewName;\r
83                         progress.Stop();\r
84                         CRenameDlg dlg;\r
85                         dlg.m_name = name;\r
86                         dlg.m_windowtitle.Format(IDS_PROC_NEWNAMEMOVE, (LPCTSTR)name);\r
87                         if (dlg.DoModal() != IDOK)\r
88                         {\r
89                                 return FALSE;\r
90                         }\r
91                         destPath.SetFromWin(droppath+_T("\\")+dlg.m_name);\r
92                 } \r
93                 CString cmd,out;\r
94                 \r
95                 cmd.Format(_T("git.exe mv -- \"%s\" \"%s\""),pathList[nPath].GetGitPathString(),destPath.GetGitPathString());\r
96                 if(g_Git.Run(cmd,&out,CP_ACP))\r
97                 {\r
98                         if (CMessageBox::Show(hwndExplorer, out, _T("TortoiseGit"), MB_YESNO)==IDYES)\r
99                         {\r
100 #if 0\r
101                                         if (!svn.Move(CTSVNPathList(pathList[nPath]), destPath, TRUE))\r
102                                         {\r
103                                                 CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseGit"), MB_ICONERROR);\r
104                                                 return FALSE;           //get out of here\r
105                                         }\r
106                                         CShellUpdater::Instance().AddPathForUpdate(destPath);\r
107 #endif\r
108                         }\r
109                         else\r
110                         {\r
111                                 //TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());\r
112                                 CMessageBox::Show(hwndExplorer, _T("Cancel"), _T("TortoiseGit"), MB_ICONERROR);\r
113                                 return FALSE;           //get out of here\r
114                         }\r
115                 } \r
116                 else\r
117                         CShellUpdater::Instance().AddPathForUpdate(destPath);\r
118                 count++;\r
119                 if (progress.IsValid())\r
120                 {\r
121                         progress.FormatPathLine(1, IDS_PROC_MOVINGPROG, pathList[nPath].GetWinPath());\r
122                         progress.FormatPathLine(2, IDS_PROC_CPYMVPROG2, destPath.GetWinPath());\r
123                         progress.SetProgress(count, pathList.GetCount());\r
124                 }\r
125                 if ((progress.IsValid())&&(progress.HasUserCancelled()))\r
126                 {\r
127                         CMessageBox::Show(hwndExplorer, IDS_SVN_USERCANCELLED, IDS_APPNAME, MB_ICONINFORMATION);\r
128                         return FALSE;\r
129                 }\r
130         }\r
131         return true;\r
132 }\r