1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 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.
20 #include "PasteCopyCommand.h"
22 #include "ProgressDlg.h"
23 #include "SysProgressDlg.h"
24 #include "MessageBox.h"
25 #include "RenameDlg.h"
27 #include "GitStatus.h"
28 #include "ShellUpdater.h"
29 #include "ProjectProperties.h"
31 bool PasteCopyCommand::Execute()
33 CString sDroppath
= parser
.GetVal(_T("droptarget"));
34 CTGitPath
dropPath(sDroppath
);
35 ProjectProperties props
;
36 props
.ReadProps(dropPath
);
37 if (dropPath
.IsAdminDir())
40 if(!dropPath
.HasAdminDir(&g_Git
.m_CurrentDir
))
44 unsigned long count
= 0;
46 orgPathList
.RemoveAdminPaths();
47 CSysProgressDlg progress
;
48 progress
.SetTitle(IDS_PROC_COPYING
);
49 progress
.SetAnimation(IDR_MOVEANI
);
50 progress
.SetTime(true);
51 progress
.ShowModeless(CWnd::FromHandle(hwndExplorer
));
52 for (int nPath
= 0; nPath
< orgPathList
.GetCount(); ++nPath
)
54 const CTGitPath
& sourcePath
= orgPathList
[nPath
];
56 CTGitPath fullDropPath
= dropPath
;
57 if (sNewName
.IsEmpty())
58 fullDropPath
.AppendPathString(sourcePath
.GetFileOrDirectoryName());
60 fullDropPath
.AppendPathString(sNewName
);
62 // Check for a drop-on-to-ourselves
63 if (sourcePath
.IsEquivalentTo(fullDropPath
))
68 dlg
.m_windowtitle
.Format(IDS_PROC_NEWNAMECOPY
, (LPCTSTR
)sourcePath
.GetUIFileOrDirectoryName());
69 if (dlg
.DoModal() != IDOK
)
73 // rebuild the progress dialog
74 progress
.EnsureValid();
75 progress
.SetTitle(IDS_PROC_COPYING
);
76 progress
.SetAnimation(IDR_MOVEANI
);
77 progress
.SetTime(true);
78 progress
.SetProgress(count
, orgPathList
.GetCount());
79 progress
.ShowModeless(CWnd::FromHandle(hwndExplorer
));
80 // Rebuild the destination path, with the new name
81 fullDropPath
.SetFromUnknown(sDroppath
);
82 fullDropPath
.AppendPathString(dlg
.m_name
);
85 //svn_wc_status_kind s = status.GetAllStatus(sourcePath);
86 //if ((s == svn_wc_status_none)||(s == svn_wc_status_unversioned)||(s == svn_wc_status_ignored))
88 // source file is unversioned: move the file to the target, then add it
89 CopyFile(sourcePath
.GetWinPath(), fullDropPath
.GetWinPath(), FALSE
);
91 cmd
.Format(_T("git.exe add \"%s\""),fullDropPath
.GetWinPath());
92 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
94 TRACE(_T("%s\n"), (LPCTSTR
)output
);
95 CMessageBox::Show(hwndExplorer
, output
, _T("TortoiseGit"), MB_ICONERROR
);
96 return FALSE
; //get out of here
99 CShellUpdater::Instance().AddPathForUpdate(fullDropPath
);
103 // if (!svn.Copy(CTSVNPathList(sourcePath), fullDropPath, SVNRev::REV_WC, SVNRev()))
105 // TRACE(_T("%s\n"), (LPCTSTR)svn.GetLastErrorMessage());
106 // CMessageBox::Show(hwndExplorer, svn.GetLastErrorMessage(), _T("TortoiseSVN"), MB_ICONERROR);
107 // return FALSE; //get out of here
110 // CShellUpdater::Instance().AddPathForUpdate(fullDropPath);
113 if (progress
.IsValid())
115 progress
.FormatPathLine(1, IDS_PROC_COPYINGPROG
, sourcePath
.GetWinPath());
116 progress
.FormatPathLine(2, IDS_PROC_CPYMVPROG2
, fullDropPath
.GetWinPath());
117 progress
.SetProgress(count
, orgPathList
.GetCount());
119 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
121 CMessageBox::Show(hwndExplorer
, IDS_SVN_USERCANCELLED
, IDS_APPNAME
, MB_ICONINFORMATION
);