1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2015 - 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 "AddProgressCommand.h"
21 #include "ShellUpdater.h"
22 #include "MassiveGitTask.h"
25 bool AddProgressCommand::Run(CGitProgressList
* list
, CString
& sWindowTitle
, int& m_itemCountTotal
, int& m_itemCount
)
27 list
->SetWindowTitle(IDS_PROGRS_TITLE_ADD
, g_Git
.CombinePath(m_targetPathList
.GetCommonRoot().GetUIPathString()), sWindowTitle
);
28 list
->SetBackgroundImage(IDI_ADD_BKG
);
29 list
->ReportCmd(CString(MAKEINTRESOURCE(IDS_PROGRS_CMD_ADD
)));
31 m_itemCountTotal
= m_targetPathList
.GetCount();
33 if (g_Git
.UsingLibGit2(CGit::GIT_CMD_ADD
))
35 CAutoRepository
repo(g_Git
.GetGitRepository());
38 list
->ReportGitError();
43 if (git_repository_index(index
.GetPointer(), repo
))
45 list
->ReportGitError();
48 if (git_index_read(index
, true))
50 list
->ReportGitError();
54 for (m_itemCount
= 0; m_itemCount
< m_itemCountTotal
; ++m_itemCount
)
56 CStringA filePathA
= CUnicodeUtils::GetMulti(m_targetPathList
[m_itemCount
].GetGitPathString(), CP_UTF8
).TrimRight(_T('/'));
57 if (git_index_add_bypath(index
, filePathA
))
59 list
->ReportGitError();
62 list
->AddNotify(new CGitProgressList::WC_File_NotificationData(m_targetPathList
[m_itemCount
], CGitProgressList::WC_File_NotificationData::git_wc_notify_add
));
64 if (list
->IsCancelled() == TRUE
)
66 list
->ReportUserCanceled();
71 if (git_index_write(index
))
73 list
->ReportGitError();
79 CMassiveGitTask
mgt(L
"add -f");
80 if (!mgt
.ExecuteWithNotify(&m_targetPathList
, list
->m_bCancelled
, CGitProgressList::WC_File_NotificationData::git_wc_notify_add
, list
))
84 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList
);
86 m_PostCmdCallback
= [](DWORD status
, PostCmdList
& postCmdList
)
91 postCmdList
.push_back(PostCmd(IDI_COMMIT
, IDS_MENUCOMMIT
, []
94 sCmd
.Format(_T("/command:commit /path:\"%s\""), (LPCTSTR
)g_Git
.m_CurrentDir
);
95 CAppUtils::RunTortoiseGitProc(sCmd
);