1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2011-2013 - TortoiseGit
4 // Copyright (C) 2006-2008 - 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.
25 #include "GitStatus.h"
28 * \ingroup TortoiseProc
29 * enumeration of all client hook types
43 * \ingroup TortoiseProc
44 * helper class, used as the key to the std::map we store
45 * the data for the client hook scripts in.
53 bool operator < (const hookkey
& hk
) const
55 if (htype
== hk
.htype
)
56 return (path
< hk
.path
);
58 return htype
< hk
.htype
;
63 * \ingroup TortoiseProc
64 * helper struct, used as the value to the std::map we
65 * store the data for the client hook scripts in.
67 typedef struct hookcmd
74 typedef std::map
<hookkey
, hookcmd
>::iterator hookiterator
;
77 * \ingroup TortoiseProc
78 * Singleton class which deals with the client hook scripts.
80 class CHooks
: public std::map
<hookkey
, hookcmd
>
85 void AddPathParam(CString
& sCmd
, const CTGitPathList
& pathList
);
86 void AddDepthParam(CString
& sCmd
, git_depth_t depth
);
87 void AddCWDParam(CString
& sCmd
, const CTGitPathList
& pathList
);
88 void AddErrorParam(CString
& sCmd
, const CString
& error
);
89 void AddParam(CString
& sCmd
, const CString
& param
);
90 CTGitPath
AddMessageFileParam(CString
& sCmd
, const CString
& message
);
92 /// Create the singleton. Call this at the start of the program.
94 /// Returns the singleton instance
95 static CHooks
& Instance();
96 /// Destroys the singleton object. Call this at the end of the program.
97 static void Destroy();
100 /// Saves the hook script information to the registry.
103 * Removes the hook script identified by \c key. To make the change persistent
106 bool Remove(const hookkey
&key
);
108 * Adds a new hook script. To make the change persistent, call Save().
110 void Add(hooktype ht
, const CTGitPath
& Path
, LPCTSTR szCmd
,
111 bool bWait
, bool bShow
);
113 /// returns the string representation of the hook type.
114 static CString
GetHookTypeString(hooktype t
);
115 /// returns the hooktype from a string representation of the same.
116 static hooktype
GetHookType(const CString
& s
);
119 * Executes the Start-Commit-Hook that first matches one of the paths in
121 * \param pathList a list of paths to look for the hook scripts
122 * \param message a commit message
123 * \param exitcode on return, contains the exit code of the hook script
124 * \param error the data the hook script outputs to stderr
125 * \remark the string "%PATHS% in the command line of the hook script is
126 * replaced with the path to a temporary file which contains a list of files
127 * in \c pathList, separated by newlines. The hook script can parse this
128 * file to get all the paths the commit is about to be done on.
129 * The string %MESSAGEFILE% is replaced with path to temporary file containing
130 * \c message. If the script finishes successfully, contents of this file
131 * is read back into \c message parameter.
133 bool StartCommit(const CTGitPathList
& pathList
, CString
& message
,
134 DWORD
& exitcode
, CString
& error
);
136 * Executes the Pre-Commit-Hook that first matches one of the paths in
138 * \param pathList a list of paths to look for the hook scripts
139 * \param depth the depth of the commit
140 * \param message the commit message
141 * \param exitcode on return, contains the exit code of the hook script
142 * \param error the data the hook script outputs to stderr
143 * \remark the string "%PATHS% in the command line of the hook script is
144 * replaced with the path to a temporary file which contains a list of files
145 * in \c pathList, separated by newlines. The hook script can parse this
146 * file to get all the paths the update is about to be done on.
147 * The string "%DEPTH%" is replaced with the numerical value (string) of the
148 * Git_depth_t parameter. See the Subversion source documentation about the
151 bool PreCommit(const CTGitPathList
& pathList
, git_depth_t depth
,
152 const CString
& message
, DWORD
& exitcode
,
155 * Executes the Post-Commit-Hook that first matches one of the paths in
157 * \param pathList a list of paths to look for the hook scripts
158 * \param depth the depth of the commit
159 * \param message the commit message
160 * \param rev the revision the commit was done to
161 * \param exitcode on return, contains the exit code of the hook script
162 * \param error the data the hook script outputs to stderr
163 * \remark the string "%PATHS% in the command line of the hook script is
164 * replaced with the path to a temporary file which contains a list of files
165 * in \c pathList, separated by newlines. The hook script can parse this
166 * file to get all the paths the commit is about to be done on.
167 * The string "%DEPTH%" is replaced with the numerical value (string) of the
168 * Git_depth_t parameter. See the Subversion source documentation about the
171 bool PostCommit(const CTGitPathList
& pathList
, git_depth_t depth
,
172 GitRev rev
, const CString
& message
,
173 DWORD
& exitcode
, CString
& error
);
175 bool PrePush(const CTGitPathList
& pathList
,DWORD
& exitcode
, CString
& error
);
176 bool PostPush(const CTGitPathList
& pathList
,DWORD
& exitcode
, CString
& error
);
179 * Starts a new process, specified in \c cmd.
180 * \param error the data the process writes to stderr
181 * \param bWait if true, then this method waits until the created process has finished. If false, then the return
182 * value will always be 0 and \c error will be an empty string.
183 * \param bShow set to true if the process should be started visible.
184 * \return the exit code of the process if \c bWait is true, zero otherwise.
186 DWORD
RunScript(CString cmd
, LPCTSTR currentDir
, CString
& error
, bool bWait
, bool bShow
);
188 * Find the hook script information for the hook type \c t which matches a
189 * path in \c pathList.
191 hookiterator
FindItem(hooktype t
, const CTGitPathList
& pathList
);
192 static CHooks
* m_pInstance
;