Skip to main content

Poirot helps you investigate your repositories. Give him a set of clues (e.g. strings or regular expressions) and he will report back any place they appear in your repository’s revision history.

When used as a pre-commit hook, Poirot can warn you if you’re about to commit something you might not intend (think passwords, private keys, tokens, and other bits of sensitive or personally identifiable information).

Poirot began as a fork of CFPB’s fellow gumshoe, Clouseau.

Dependencies

  • git

  • Python 2.7 or 3.3+

  • a UNIX-based OS (e.g. Mac or Linux) or a UNIX-y shell on Windows (e.g. Cygwin, Babun, or Git-Bash). It will not work with the default Windows Command Prompt (cmd).

Poirot uses these Python packages:

  • Jinja2 to format its console output

  • tqdm to display a progress bar

  • regex to allow for POSIX ERE regular expressions

  • requests to read remote pattern files

Installation

Poirot is available on PyPi and can be installed with pip as:

pip install poirot

You may want to install it in a virtual environment, unless you plan on using Poirot in a global commit hook.

In that case, you will have to ensure that you have done a global pip install for any Python versions you are using. E.g., if you want to run it on Python 2.7, 3.3, and 3.5 installed, install Poirot as follows:

pip2.7 install poirot
pip3.3 install poirot
pip3.5 install poirot

Running Poirot from the Command Line

To invoke Poirot and see his findings, call him from the command line with poirot and the following optional arguments:

  • –url: The repository’s URL, e.g. https://github.com/DCgov/poirot.git or git@github.com:DCgov/poirot.git. When included, you will be given the choice to clone or pull from the remote URL. Default value: none.

  • –dir: The local path to your repository’s base directory or the directory you would like to clone or pull to. Default value: the current working directory.

  • –term: A single term or regular expression to search for. Default value: none.

  • –patterns: The path to a .txt file with strings or regular expression patterns, each on its own line. These can be the file’s URL or its relative or absolute local path. You can give a comma-separated list of pattern files, if you wish to include more than one. Default value: default.txt.

  • –staged: A flag, which when included, restricts search to staged revisions. This is helpful, along with --dir, as part of a pre-commit hook.

  • –revlist: A range of revisions to inspect. Default value: The last commit (i.e. HEAD^!) if --staged is not included, otherwise none.

  • –verbose: A flag to output verbose, colorful output and pattern-match highlighting. The GIF above gives an example with –verbose included.

  • –before: Date restriction on revisions. Default value: none.

  • –after: Date restriction on revisions. Default value: none.

  • –author: Authorship restriction on revisions. Default value: none.

  • –output: File to output results as JSON. Default value: none.

Examples

The most basic command Poirot will accept is:

poirot

That will search the current git directory’s last commit (i.e. HEAD^!) for the patterns in the default pattern file.

To specify one or more different patterns files (each separated by a comma), do this instead:

poirot --patterns='../path/to/thisisapatternfile.txt,/Users/myusername/anotherpatternfile.txt'

The –patterns option also allows files accessible over HTTP, like this one here:

poirot --patterns='https://raw.githubusercontent.com/DCgov/poirot/master/poirot/patterns/default.txt'

To search for a single term (like password):

poirot --term="password"

Say you want to search for password in the whole revision history of all branches. Then do:

poirot --term="password" --revlist="all"

You can further restrict the set of revisions Poirot looks through with the before, after, and author options (which correspond to the same flags in git). E.g.:

poirot --term="password" --revlist=40dc6d1...3e4c011 --before="2015-11-28" --after="2015-10-01" --author="me@poirot.com"

Perhaps you don’t have the repository available locally or you would like to update it from a remote URL. Just add the url to your command and it will allow you to clone or pull to the current folder.

poirot --url https://github.com/foo/baz.git --term="password"

You can also specify a different directory than the current one with dir. The following command will clone/pull to the folder thisotherfolder, which sits inside of the current directory. If it does not yet exist, it will be created.

poirot --url https://github.com/foo/baz.git --term="password" --dir="thisotherfolder"

To search changes that have been staged for commit, but not yet committed, use the staged flag:

poirot --term="password" --staged

Release files for poirot 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for poirot 1.0.1
File Size Uploaded
poirot-1.0.1.tar.gz 17.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for poirot 1.0.1
File Interpreter ABI Platform
poirot-1.0.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 38.0 kB

Release files / poirot-1.0.1.tar.gz

Download URL poirot-1.0.1.tar.gz
Size 17.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3437901a1e6368b367a2412c7c6f53c962cb2e941f22866bdc41eba2700c1fc3
BLAKE2b-256 checksum
How to use checksums
041b50b77d35d438c0db30aef4404d3e82894bd980d2dba88774874e95c331aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / poirot-1.0.1-py2.py3-none-any.whl

Download URL poirot-1.0.1-py2.py3-none-any.whl
Size 20.9 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
fab31c089b99dabd4fd5bea7616a4475063455ae64c8b8b70d46888cebe7ae88
BLAKE2b-256 checksum
How to use checksums
9c5bea5405ee6c03ef77fd06c281d20c57577e2da2615097a5f88817a6e3ca30
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page