SetGitNote -> SetGitNotes
[TortoiseGit.git] / src / TortoiseProc / ProgressCommands / ResetProgressCommand.cpp
blob177bddab14cf25d6746daa985c9872cc563f169b
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-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 "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)) + L' ' + CString(MAKEINTRESOURCE(resetTypesResource[m_resetType])) + L' ' + m_revision);
38 list->ShowProgressBar();
39 CAutoRepository repo(g_Git.GetGitRepository());
40 if (!repo)
42 list->ReportGitError();
43 return false;
46 CGitProgressList::Payload cbpayload = { list, repo };
47 git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT;
49 CBlockCacheForPath block(g_Git.m_CurrentDir);
50 CAutoObject target;
51 if (git_revparse_single(target.GetPointer(), repo, CUnicodeUtils::GetUTF8(m_revision)))
52 goto error;
53 checkout_options.progress_payload = &cbpayload;
54 checkout_options.progress_cb = [](const char*, size_t completed_steps, size_t total_steps, void* payload)
56 CGitProgressList::Payload* cbpayload = (CGitProgressList::Payload*)payload;
57 cbpayload->list->m_itemCountTotal = (int)total_steps;
58 cbpayload->list->m_itemCount = (int)completed_steps;
60 checkout_options.notify_cb = [](git_checkout_notify_t, const char* pPath, const git_diff_file*, const git_diff_file*, const git_diff_file*, void* payload) -> int
62 CGitProgressList* list = (CGitProgressList*)payload;
63 CString path(CUnicodeUtils::GetUnicode(pPath));
64 if (DWORD(CRegDWORD(L"Software\\TortoiseGit\\RevertWithRecycleBin", TRUE)))
66 if (!CTGitPath(g_Git.CombinePath(path)).Delete(true, true))
68 list->ReportError(L"Could move \"" + path + L"\" to recycle bin");
69 return GIT_EUSER;
72 list->AddNotify(new CGitProgressList::WC_File_NotificationData(path, CGitProgressList::WC_File_NotificationData::git_wc_notify_checkout));
73 return 0;
75 checkout_options.notify_flags = GIT_CHECKOUT_NOTIFY_UPDATED;
76 checkout_options.notify_payload = list;
77 if (git_reset(repo, target, (git_reset_t)(m_resetType + 1), &checkout_options))
78 goto error;
80 // Not setting m_PostCmdCallback here, as clone is only called from AppUtils.cpp
82 return true;
84 error:
85 list->ReportGitError();
86 return false;