Update libgit2
[TortoiseGit.git] / src / TortoiseProc / ProgressCommands / ResetProgressCommand.cpp
blobbcb2846dc564f9f5693b5a654ab243d5bda124fc
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2014 - 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 "ResetProgressCommand.h"
21 #include "AppUtils.h"
22 #include "../TGitCache/CacheInterface.h"
24 bool ResetProgressCommand::Run(CGitProgressList* list, CString& sWindowTitle, int& /*m_itemCountTotal*/, int& /*m_itemCount*/)
26 if (!g_Git.UsingLibGit2(CGit::GIT_CMD_RESET))
28 // should never run to here
29 ASSERT(0);
30 return false;
33 list->SetWindowTitle(IDS_PROGRS_TITLE_RESET, g_Git.m_CurrentDir, sWindowTitle);
34 list->SetBackgroundImage(IDI_UPDATE_BKG);
35 int resetTypesResource[] = { IDS_RESET_SOFT, IDS_RESET_MIXED, IDS_RESET_HARD };
36 list->ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_TITLE_RESET)) + _T(" ") + CString(MAKEINTRESOURCE(resetTypesResource[m_resetType])) + _T(" ") + m_revision);
38 list->ShowProgressBar();
39 CAutoRepository repo(g_Git.GetGitRepository());
40 if (!repo)
42 list->ReportGitError();
43 return false;
46 CBlockCacheForPath block(g_Git.m_CurrentDir);
47 CAutoObject target;
48 if (git_revparse_single(target.GetPointer(), repo, CUnicodeUtils::GetUTF8(m_revision)))
49 goto error;
50 if (git_reset(repo, target, (git_reset_t)(m_resetType + 1), nullptr, nullptr, nullptr))
51 goto error;
53 // Not setting m_PostCmdCallback here, as clone is only called from AppUtils.cpp
55 return true;
57 error:
58 list->ReportGitError();
59 return false;