Fixed issue #3668: "Revert to revision" fails for added files
[TortoiseGit.git] / src / TortoiseProc / ProjectProperties.h
bloba62d09729ef0cc769946d82c95c7ba5185fd9db8
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2009, 2011-2014, 2018, 2020 - TortoiseGit
4 // Copyright (C) 2003-2008,2011-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 #pragma once
21 #include "TGitPath.h"
22 #include <regex>
24 #define BUGTRAQPROPNAME_LABEL L"bugtraq.label"
25 #define BUGTRAQPROPNAME_MESSAGE L"bugtraq.message"
26 #define BUGTRAQPROPNAME_NUMBER L"bugtraq.number"
27 #define BUGTRAQPROPNAME_LOGREGEX L"bugtraq.logregex"
28 #define BUGTRAQPROPNAME_URL L"bugtraq.url"
29 #define BUGTRAQPROPNAME_WARNIFNOISSUE L"bugtraq.warnifnoissue"
30 #define BUGTRAQPROPNAME_APPEND L"bugtraq.append"
31 #define BUGTRAQPROPNAME_PROVIDERUUID L"bugtraq.provideruuid"
32 #define BUGTRAQPROPNAME_PROVIDERUUID64 L"bugtraq.provideruuid64"
33 #define BUGTRAQPROPNAME_PROVIDERPARAMS L"bugtraq.providerparams"
35 #define PROJECTPROPNAME_LOGWIDTHLINE L"tgit.logwidthmarker"
36 #define PROJECTPROPNAME_LOGMINSIZE L"tgit.logminsize"
37 #define PROJECTPROPNAME_LOGFILELISTLANG L"tsvn.logfilelistenglish"
38 #define PROJECTPROPNAME_PROJECTLANGUAGE L"tgit.projectlanguage"
39 #define PROJECTPROPNAME_WARNNOSIGNEDOFFBY L"tgit.warnnosignedoffby"
40 #define PROJECTPROPNAME_ICON L"tgit.icon"
42 #define PROJECTPROPNAME_WEBVIEWER_REV L"webviewer.revision"
43 #define PROJECTPROPNAME_WEBVIEWER_PATHREV L"webviewer.pathrevision"
45 #define PROJECTPROPNAME_STARTCOMMITHOOK L"hook.startcommit."
46 #define PROJECTPROPNAME_PRECOMMITHOOK L"hook.precommit."
47 #define PROJECTPROPNAME_POSTCOMMITHOOK L"hook.postcommit."
48 #define PROJECTPROPNAME_PREPUSHHOOK L"hook.prepush."
49 #define PROJECTPROPNAME_POSTPUSHHOOK L"hook.postpush."
50 #define PROJECTPROPNAME_PREREBASEHOOK L"hook.prerebase."
52 /**
53 * \ingroup TortoiseProc
54 * Provides methods for retrieving information about bug/issue trackers
55 * associated with a git repository/working copy and other project
56 * related properties.
58 class ProjectProperties
60 public:
61 ProjectProperties(void);
63 /**
64 * Reads the properties from the current working tree
66 BOOL ReadProps();
68 public:
69 /**
70 * Searches for the BugID inside a log message. If one is found,
71 * the method returns TRUE. The rich edit control is used to set
72 * the CFE_LINK effect on the BugID's.
73 * \param msg the log message
74 * \param pWnd Pointer to a rich edit control
76 #ifdef _RICHEDIT_
77 std::vector<CHARRANGE> FindBugIDPositions(const CString& msg);
78 #endif
79 BOOL FindBugID(const CString& msg, CWnd * pWnd);
81 CString FindBugID(const CString& msg);
82 std::set<CString> FindBugIDs(const CString& msg);
84 /**
85 * Check whether calling \ref FindBugID or \ref FindBugIDPositions
86 * is worthwhile. If the result is @a false, those functions would
87 * return empty strings or sets, respectively.
89 bool MightContainABugID();
91 /**
92 * Searches for the BugID inside a log message. If one is found,
93 * that BugID is returned. If none is found, an empty string is returned.
94 * The \c msg is trimmed off the BugID.
96 CString GetBugIDFromLog(CString& msg);
98 /**
99 * Checks if the bug ID is valid. If bugtraq:number is 'true', then the
100 * functions checks if the bug ID doesn't contain any non-number chars in it.
102 BOOL CheckBugID(const CString& sID);
105 * Checks if the log message \c sMessage contains a bug ID. This is done by
106 * using the bugtraq:checkre property.
108 BOOL HasBugID(const CString& sMessage);
111 * Returns the URL pointing to the Issue in the issue tracker. The URL is
112 * created from the bugtraq:url property and the BugID found in the log message.
113 * \param msg the BugID extracted from the log message
115 CString GetBugIDUrl(const CString& sBugID);
118 * Replaces %BUGID% in the provided URL with the sBugID after doing URL encoding
120 static void ReplaceBugIDPlaceholder(CString& url, const CString& sBugID);
122 /** replaces bNumer: a regular expression string to check the validity of
123 * the entered bug ID. */
124 const CString& GetCheckRe() const {return sCheckRe;}
125 void SetCheckRe(const CString& s) {sCheckRe = s;regExNeedUpdate=true;AutoUpdateRegex();}
127 /** used to extract the bug ID from the string matched by sCheckRe */
128 const CString& GetBugIDRe() const {return sBugIDRe;}
129 void SetBugIDRe(const CString& s) {sBugIDRe = s;regExNeedUpdate=true;AutoUpdateRegex();}
131 #ifdef _WIN64
132 const CString& GetProviderUUID() const { return (sProviderUuid64.IsEmpty() ? sProviderUuid : sProviderUuid64); }
133 #else
134 const CString& GetProviderUUID() const { return (sProviderUuid.IsEmpty() ? sProviderUuid64 : sProviderUuid); }
135 #endif
137 public:
138 /** The label to show in the commit dialog where the issue number/bug id
139 * is entered. Example: "Bug-ID: " or "Issue-No.:". Default is "Bug-ID :" */
140 CString sLabel;
142 /** The message string to add below the log message the user entered.
143 * It must contain the string "%BUGID%" which gets replaced by the client
144 * with the issue number / bug id the user entered. */
145 CString sMessage;
147 /** If this is set, then the bug-id / issue number must be a number, no text */
148 BOOL bNumber;
150 /** replaces bNumer: a regular expression string to check the validity of
151 * the entered bug ID. */
152 CString sCheckRe;
154 /** used to extract the bug ID from the string matched by sCheckRe */
155 CString sBugIDRe;
157 /** The url pointing to the issue tracker. If the url contains the string
158 * "%BUGID% the client has to replace it with the issue number / bug id
159 * the user entered. */
160 CString sUrl;
162 /** If set to TRUE, show a warning dialog if the user forgot to enter
163 * an issue number in the commit dialog. */
164 BOOL bWarnIfNoIssue;
166 /** If set to FALSE, then the bug tracking entry is inserted at the top of the
167 log message instead of at the bottom. Default is TRUE */
168 BOOL bAppend;
170 /** the parameters passed to the COM bugtraq provider which implements the
171 IBugTraqProvider interface */
172 CString sProviderParams;
174 /** The number of chars the width marker should be shown at. If the property
175 * is not set, then this value is 80 by default. */
176 int nLogWidthMarker;
178 /** Minimum size a log message must have in chars */
179 int nMinLogSize;
181 /** TRUE if the file list to be inserted in the commit dialog should be in
182 * English and not in the localized language. Default is TRUE */
183 BOOL bFileListInEnglish;
185 /** The language identifier this project uses for log messages. */
186 LONG lProjectLanguage;
188 /** The url pointing to the web viewer. The string %REVISION% is replaced
189 * with the revision number, "HEAD", or a date */
190 CString sWebViewerRev;
192 /** The url pointing to the web viewer. The string %REVISION% is replaced
193 * with the revision number, "HEAD", or a date. The string %PATH% is replaced
194 * with the path relative to the repository root, e.g. "/trunk/src/file" */
195 CString sWebViewerPathRev;
197 BOOL bWarnNoSignedOffBy;
198 CString sIcon;
201 * A regex string to extract revisions from a log message.
203 CString sLogRevRegex;
205 /** the COM uuid of the bugtraq provider which implements the IBugTraqProvider
206 interface. */
207 CString sProviderUuid;
208 CString sProviderUuid64;
210 /// multi line string containing the data for a start-commit-hook
211 CString sStartCommitHook;
212 /// multi line string containing the data for a pre-commit-hook
213 CString sPreCommitHook;
214 /// multi line string containing the data for a post-commit-hook
215 CString sPostCommitHook;
216 /// multi line string containing the data for a pre-push-hook
217 CString sPrePushHook;
218 /// multi line string containing the data for a post-push-hook
219 CString sPostPushHook;
220 /// multi line string containing the data for a pre-rebase-hook
221 CString sPreRebaseHook;
223 private:
225 * Constructing regex objects is expensive. Therefore, cache them here.
227 void AutoUpdateRegex();
229 void FetchHookString(CAutoConfig& gitconfig, const CString& sBase, CString& sHook);
231 bool regExNeedUpdate;
232 std::wregex regCheck;
233 std::wregex regBugID;
235 int nBugIdPos; ///< result of sMessage.Find(L"%BUGID%");
237 #ifdef GTEST_INCLUDE_GTEST_GTEST_H_
238 FRIEND_TEST(ProjectPropertiesTest, ParseBugIDs);
239 #endif