1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2008, 2012-2013, 2015-2017 - 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.
20 #include "PasteMoveCommand.h"
22 #include "SysProgressDlg.h"
23 #include "MessageBox.h"
25 #include "RenameDlg.h"
26 #include "ShellUpdater.h"
28 bool PasteMoveCommand::Execute()
30 CString sDroppath
= parser
.GetVal(L
"droptarget");
31 CTGitPath
dropPath(sDroppath
);
32 if (dropPath
.IsAdminDir())
35 if(!dropPath
.HasAdminDir(&g_Git
.m_CurrentDir
))
38 unsigned long count
= 0;
39 orgPathList
.RemoveAdminPaths();
41 CSysProgressDlg progress
;
42 progress
.SetTitle(IDS_PROC_MOVING
);
43 progress
.SetTime(true);
44 progress
.ShowModeless(CWnd::FromHandle(hwndExplorer
));
45 for (int nPath
= 0; nPath
< orgPathList
.GetCount(); ++nPath
)
48 if (sNewName
.IsEmpty())
49 destPath
= CTGitPath(sDroppath
+ L
'\\' + orgPathList
[nPath
].GetFileOrDirectoryName());
51 destPath
= CTGitPath(sDroppath
+ L
'\\' + sNewName
);
52 if (destPath
.Exists())
54 CString name
= orgPathList
[nPath
].GetFileOrDirectoryName();
55 if (!sNewName
.IsEmpty())
60 dlg
.m_windowtitle
.Format(IDS_PROC_NEWNAMEMOVE
, (LPCTSTR
)name
);
61 if (dlg
.DoModal() != IDOK
)
63 destPath
.SetFromWin(sDroppath
+ L
'\\' + dlg
.m_name
);
66 orgPathList
[nPath
].HasAdminDir(&top
);
67 //git_wc_status_kind s = status.GetAllStatus(orgPathList[nPath]);
68 //if (s == git_wc_status_none || s == git_wc_status_unversioned || s == git_wc_status_ignored || top.CompareNoCase(g_Git.m_CurrentDir) != 0)
71 // source file is unversioned: move the file to the target, then add it
72 MoveFile(orgPathList
[nPath
].GetWinPath(), destPath
.GetWinPath());
74 cmd
.Format(L
"git.exe add -- \"%s\"", destPath
.GetWinPath());
75 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
76 //if (!Git.Add(CTGitorgPathList(destPath), &props, Git_depth_infinity, true, false, true))
78 TRACE(L
"%s\n", (LPCTSTR
)output
);
79 CMessageBox::Show(hwndExplorer
, output
, L
"TortoiseGit", MB_ICONERROR
);
80 return FALSE
; //get out of here
82 CShellUpdater::Instance().AddPathForUpdate(destPath
);
87 cmd
.Format(L
"git.exe mv \"%s\" \"%s\"", (LPCTSTR
)orgPathList
[nPath
].GetGitPathString(), (LPCTSTR
)destPath
.GetGitPathString());
88 if (g_Git
.Run(cmd
, &output
, CP_UTF8
))
89 //if (!Git.Move(CTGitorgPathList(orgPathList[nPath]), destPath, FALSE))
92 if (Git
.Err
&& (Git
.Err
->apr_err
== Git_ERR_UNVERSIONED_RESOURCE
||
93 Git
.Err
->apr_err
== Git_ERR_CLIENT_MODIFIED
))
95 // file/folder seems to have local modifications. Ask the user if
96 // a force is requested.
97 CString temp
= Git
.GetLastErrorMessage();
98 CString
sQuestion(MAKEINTRESOURCE(IDS_PROC_FORCEMOVE
));
99 temp
+= L
'\n' + sQuestion
;
100 if (CMessageBox::Show(hwndExplorer
, temp
, L
"TortoiseGit", MB_YESNO
) == IDYES
)
102 if (!Git
.Move(CTGitPathList(pathList
[nPath
]), destPath
, TRUE
))
104 CMessageBox::Show(hwndExplorer
, Git
.GetLastErrorMessage(), L
"TortoiseGit", MB_ICONERROR
);
105 return FALSE
; //get out of here
107 CShellUpdater::Instance().AddPathForUpdate(destPath
);
113 TRACE(L
"%s\n", (LPCTSTR
)output
);
114 CMessageBox::Show(hwndExplorer
, output
, L
"TortoiseGit", MB_ICONERROR
);
115 return FALSE
; //get out of here
119 CShellUpdater::Instance().AddPathForUpdate(destPath
);
122 if (progress
.IsValid())
124 progress
.FormatPathLine(1, IDS_PROC_MOVINGPROG
, orgPathList
[nPath
].GetWinPath());
125 progress
.FormatPathLine(2, IDS_PROC_CPYMVPROG2
, destPath
.GetWinPath());
126 progress
.SetProgress(count
, orgPathList
.GetCount());
128 if ((progress
.IsValid())&&(progress
.HasUserCancelled()))
130 CMessageBox::Show(hwndExplorer
, IDS_USERCANCELLED
, IDS_APPNAME
, MB_ICONINFORMATION
);