Block path while we are reverting files
[TortoiseGit.git] / src / TortoiseProc / ProgressCommands / RevertProgressCommand.cpp
blob5d04298f1267cb5b2aa9c0056b89a44d47867b16
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2014, 2016 - 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 "RevertProgressCommand.h"
21 #include "ShellUpdater.h"
22 #include "AppUtils.h"
23 #include "../TGitCache/CacheInterface.h"
25 bool RevertProgressCommand::Run(CGitProgressList* list, CString& sWindowTitle, int& m_itemCountTotal, int& m_itemCount)
27 list->SetWindowTitle(IDS_PROGRS_TITLE_REVERT, g_Git.CombinePath(m_targetPathList.GetCommonRoot().GetUIPathString()), sWindowTitle);
28 list->SetBackgroundImage(IDI_REVERT_BKG);
30 CBlockCacheForPath block(g_Git.m_CurrentDir);
32 m_itemCountTotal = 2 * m_targetPathList.GetCount();
33 CTGitPathList delList;
34 for (m_itemCount = 0; m_itemCount < m_targetPathList.GetCount(); ++m_itemCount)
36 CTGitPath path;
37 int action;
38 path.SetFromWin(g_Git.CombinePath(m_targetPathList[m_itemCount]));
39 action = m_targetPathList[m_itemCount].m_Action;
40 /* rename file can't delete because it needs original file*/
41 if ((!(action & CTGitPath::LOGACTIONS_ADDED)) &&
42 (!(action & CTGitPath::LOGACTIONS_REPLACED)))
43 delList.AddPath(path);
45 if (DWORD(CRegDWORD(_T("Software\\TortoiseGit\\RevertWithRecycleBin"), TRUE)))
46 delList.DeleteAllFiles(true);
48 list->ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_REVERT)));
49 for (int i = 0; i < m_targetPathList.GetCount(); ++i)
51 CString err;
52 if (g_Git.Revert(_T("HEAD"), (CTGitPath&)m_targetPathList[i], err))
54 list->ReportError(_T("Revert failed:\n") + err);
55 return false;
57 list->AddNotify(new CGitProgressList::WC_File_NotificationData(m_targetPathList[i], CGitProgressList::WC_File_NotificationData::git_wc_notify_revert));
58 ++m_itemCount;
60 if (list->IsCancelled() == TRUE)
62 list->ReportUserCanceled();
63 return false;
67 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
69 return true;