Add more checks for git repository before executing commands
[TortoiseGit.git] / src / TortoiseProc / Commands / ResolveCommand.cpp
blobb6e16ec49a98e5913058ad7a2403e41cd9e0203e
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009-2016, 2018-2019 - TortoiseGit
4 // Copyright (C) 2007-2008,2012 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "ResolveCommand.h"
22 #include "MessageBox.h"
23 #include "AppUtils.h"
24 #include "ResolveDlg.h"
25 #include "GitProgressDlg.h"
26 #include "ProgressCommands/ResolveProgressCommand.h"
28 bool ResolveCommand::Execute()
30 if (!GitAdminDir::HasAdminDir(g_Git.m_CurrentDir))
32 CMessageBox::Show(GetExplorerHWND(), IDS_NOWORKINGCOPY, IDS_APPNAME, MB_ICONERROR);
33 return false;
36 CResolveDlg dlg;
37 dlg.m_pathList = pathList;
38 INT_PTR ret = IDOK;
39 if (!parser.HasKey(L"noquestion"))
40 ret = dlg.DoModal();
41 if (ret == IDOK)
43 if (!dlg.m_pathList.IsEmpty())
45 if (parser.HasKey(L"silent"))
47 for (int i = 0; i < dlg.m_pathList.GetCount(); ++i)
49 CString cmd, out;
50 cmd.Format(L"git.exe add -f -- \"%s\"", (LPCTSTR)dlg.m_pathList[i].GetGitPathString());
51 if (g_Git.Run(cmd, &out, CP_UTF8))
53 MessageBox(GetExplorerHWND(), out, L"TortoiseGit", MB_OK | MB_ICONERROR);
54 return false;
57 CAppUtils::RemoveTempMergeFile((CTGitPath &)dlg.m_pathList[i]);
60 HWND resolveMsgWnd = parser.HasVal(L"resolvemsghwnd") ? (HWND)parser.GetLongLongVal(L"resolvemsghwnd") : 0;
61 if (resolveMsgWnd && CRegDWORD(L"Software\\TortoiseGit\\RefreshFileListAfterResolvingConflict", TRUE) == TRUE)
63 static UINT WM_REVERTMSG = RegisterWindowMessage(L"GITSLNM_NEEDSREFRESH");
64 ::PostMessage(resolveMsgWnd, WM_REVERTMSG, NULL, NULL);
66 return true;
68 else
70 CGitProgressDlg progDlg(CWnd::FromHandle(GetExplorerHWND()));
71 theApp.m_pMainWnd = &progDlg;
72 ResolveProgressCommand resolveProgressCommand;
73 progDlg.SetCommand(&resolveProgressCommand);
74 resolveProgressCommand.SetPathList(dlg.m_pathList);
75 progDlg.DoModal();
76 return !progDlg.DidErrorsOccur();
80 return false;