Improve error message for !IsWorkingTreeOrBareRepo case
[TortoiseGit.git] / src / TortoiseProc / Commands / LogCommand.cpp
bloba8c1181f0dc26af27e18d5ba70f6593c5d6d695d
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2007-2008,2011 - TortoiseSVN
4 // Copyright (C) 2008-2016, 2018-2019 - TortoiseGit
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 "LogCommand.h"
22 #include "StringUtils.h"
23 #include "LogDlg.h"
24 #include "MessageBox.h"
25 #include "GitAdminDir.h"
27 bool LogCommand::Execute()
29 if (!GitAdminDir::IsWorkingTreeOrBareRepo(g_Git.m_CurrentDir))
31 CMessageBox::Show(GetExplorerHWND(), IDS_NOGITREPO, IDS_APPNAME, MB_ICONERROR);
32 return false;
35 //the log command line looks like this:
36 //command:log path:<path_to_file_or_directory_to_show_the_log_messages> [startrev:<startrevision>] [endrev:<endrevision>]
38 CString range;
40 CString revstart = parser.GetVal(L"startrev");
41 if (revstart.IsEmpty())
43 // support deprecated parameter prior 1.5.0
44 revstart = parser.GetVal(L"revstart");
46 if (revstart == GIT_REV_ZERO)
47 revstart.Empty();
48 if (!revstart.IsEmpty())
49 range.Format(L"%s..", (LPCTSTR)g_Git.FixBranchName(revstart));
51 CString revend = parser.GetVal(L"endrev");
52 if (revend.IsEmpty())
54 // support deprecated parameter prior 1.5.0
55 revend = parser.GetVal(L"revend");
57 if (revend == GIT_REV_ZERO)
58 revend.Empty();
59 if (!revend.IsEmpty())
60 range += g_Git.FixBranchName(revend);
62 if (parser.HasVal(L"range"))
63 range = parser.GetVal(L"range");
65 CString val = parser.GetVal(L"limit");
66 int limit = _wtoi(val);
68 int scale = -1;
69 val.MakeLower();
70 if (val.Find(L"week") > 0)
71 scale = CFilterData::SHOW_LAST_N_WEEKS;
72 else if (val.Find(L"month") > 0)
73 scale = CFilterData::SHOW_LAST_N_MONTHS;
74 else if (val.Find(L"year") > 0)
75 scale = CFilterData::SHOW_LAST_N_YEARS;
76 else if (val.Find(L"commit") > 0 || limit > 0)
77 scale = CFilterData::SHOW_LAST_N_COMMITS;
78 else if (val == L"0")
79 scale = CFilterData::SHOW_NO_LIMIT;
81 CString rev = parser.GetVal(L"rev");
83 CString findStr = parser.GetVal(L"findstring");
84 LONG findType = parser.GetLongVal(L"findtype");
85 bool findRegex = !!CRegDWORD(L"Software\\TortoiseGit\\UseRegexFilter", FALSE);
86 if (parser.HasKey(L"findtext"))
87 findRegex = false;
88 if (parser.HasKey(L"findregex"))
89 findRegex = true;
91 CLogDlg dlg;
92 theApp.m_pMainWnd = &dlg;
93 dlg.SetParams(orgCmdLinePath, cmdLinePath, rev, range, limit, scale);
94 dlg.SetFilter(findStr, findType, findRegex);
95 if (parser.HasVal(L"outfile"))
97 dlg.SetSelect(true);
98 dlg.SingleSelection(true);
100 dlg.DoModal();
101 if (parser.HasVal(L"outfile"))
103 CString sText;
104 if (!dlg.GetSelectedHash().empty())
105 sText = dlg.GetSelectedHash().at(0).ToString();
106 CStringUtils::WriteStringToTextFile(parser.GetVal(L"outfile"), (LPCTSTR)sText, true);
108 return true;