Grep across multiple git repositories.
Returns matching commit log entries or diff lines, or a specific full diff, for all git repositories in the parent directory. Includes a preview option for the key shell commands generated and a self-test.
For insight and consistency across projects more quickly and simply.
The glep command takes one or more arguments, the search terms:
glep <search_term>[ ...]
The default root directory is the parent - ../ - which is set close to the top of the source file. The terms are sought for the root directory, if a git repo, and for each top-level git repo in the root.
The search is performed by default in the output of git log using --branches=*, --oneline and --format="%S | %as %an | %h %s", with the matching log entries printed preceded by the path to the given git repo.
The git repositories to be included can be listed with the =list or =l flag (see Options below).
One term may be an alternative root directory, preceded by the two characters '=/':
glep =/<path_to_root>[ ...]
One term may also be an alternative format string, preceded by the two characters '=%':
glep =%<format_string>[ ...]
This will be passed to git log with the --format flag to set the structure of each line of output.
One term may also be all or part of the commit author name, preceded by the two characters '=@':
glep =@<author_name>[ ...]
This will be passed to git log with the --author flag to filter the results.
One term may instead be a seven-character hexadecimal commit object name, preceded by the two characters '=#':
glep =#<object_name>[ ...]
If this is the sole search term provided, the entire diff for that commit is shown, per git show. With additional search terms, only the matching lines of the diff are printed.
=/- an alternative root directory ('../' by default); secondary prefix=>also available=%- an alternative format string ('%S | %as %an | %h %s' by default)=@- the commit author=#- a seven-character hexadecimal commit object name
The script invokes itself and is assumed in doing so to have been made both executable, via a command like chmod +x glep, and available from any directory, e.g. by placing it in the '/bin' or '/usr/bin' directory.
The hashbang at the top of the file assumes the presence of Gawk in '/usr/bin', the source code that Gawk, several other utils and Git itself are installed and can be invoked directly, e.g. Git with git. A list can be found close to the top of the file, as well as in the help text.
The following sets of core default values are defined in the defaults_set function close to the base of the source file:
settings, for the root directory and format string for output, and at runtime user-provided valuesvariants, for the specially formatted search terms (t) and option flags (f)
Running the self-test after making changes plus extending or adding test cases to cover new behaviour is recommended. The self-test is run with the =test or =T flag (see Options below). The test cases are set in the test_perform function at the base of the file.
The following can be passed to glep as if a search term:
=regexp-extended/=e, to use extended regular expressions in search terms=preview/=p, to show the command for the root directory then exit=list/=l, to list the git repositories included, not searching=version/=v, to show name and version number then exit=help/=h, to show help text, incl. terms and flags, then exit=test/=T, to perform the self-test then exit
Note for all flags the use of the leading character =. Flags using the more common -/-- are interpreted as options for Gawk itself.
The following are the expected next steps in the development of the code base. The general medium-term aim is a more configurable, portable and robust implementation. Pull requests are welcome for these and other potential improvements.
- add a +/- number and pre-/post-date term for commit range
- revise help text generation for listing order and width
- add automatic dependency checking with notification
- extend argument handling for short flag clustering
- allow for an alternative executable name