Can use libgit2 to add an unregistered submodule to index
[TortoiseGit.git] / src / TortoiseProc / ProgressCommands / AddProgressCommand.cpp
blobff5db9a6a46125da6f0d4110d376ec8f853ed87f
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.
19 #include "stdafx.h"
20 #include "AddProgressCommand.h"
21 #include "ShellUpdater.h"
22 #include "MassiveGitTask.h"
23 #include "AppUtils.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());
36 if (!repo)
38 list->ReportGitError();
39 return false;
42 CAutoIndex index;
43 if (git_repository_index(index.GetPointer(), repo))
45 list->ReportGitError();
46 return false;
48 if (git_index_read(index, true))
50 list->ReportGitError();
51 return false;
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();
60 return false;
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();
67 return false;
71 if (git_index_write(index))
73 list->ReportGitError();
74 return false;
77 else
79 CMassiveGitTask mgt(L"add -f");
80 if (!mgt.ExecuteWithNotify(&m_targetPathList, list->m_bCancelled, CGitProgressList::WC_File_NotificationData::git_wc_notify_add, list))
81 return false;
84 CShellUpdater::Instance().AddPathsForUpdate(m_targetPathList);
86 m_PostCmdCallback = [](DWORD status, PostCmdList& postCmdList)
88 if (status)
89 return;
91 postCmdList.push_back(PostCmd(IDI_COMMIT, IDS_MENUCOMMIT, []
93 CString sCmd;
94 sCmd.Format(_T("/command:commit /path:\"%s\""), (LPCTSTR)g_Git.m_CurrentDir);
95 CAppUtils::RunTortoiseGitProc(sCmd);
96 }));
99 return true;