From 7ac8fe03f5e2d6817e53ff61713cef681f4c71de Mon Sep 17 00:00:00 2001
From: Alexander
Date: Thu, 17 Jun 2021 18:07:49 +0200
Subject: [PATCH 1/2] Use podman instead of docker executable
Look for podman as an exeuctable for running the container.
If not found, look for docker as well.
---
README.md | 34 ++++++++++++++++++++++------------
1 file changed, 22 insertions(+), 12 deletions(-)
diff --git a/README.md b/README.md
index e5360f3..34ee322 100644
--- a/README.md
+++ b/README.md
@@ -2,7 +2,7 @@
[Pre-commit](http://pre-commit.com/) is a tool created by Yelp that allows you to run pre-commit sanity checks against your repo, to do things like ensuring private keys aren't being added etc. This image packages `pre-commit` in a docker-container, so you can ship it with a setup script you might be using to setup local development environment.
# Usage
-- Create `.pre-commit-config.yaml` in the root of your repo. For example
+- Create `.pre-commit-config.yaml` in the root of your repo. For example
```yaml
- repo: git://github.com/pre-commit/pre-commit-hooks
@@ -19,21 +19,33 @@
```
- Add `pre-commit` script to `.git/hooks/pre-commit`
```shell
- cd $(git rev-parse --show-toplevel)
+ #!/bin/sh
+ toplevel="`git rev-parse --show-toplevel`"
+ cd "$toplevel"
- NAME=$(basename `git rev-parse --show-toplevel`)_precommit
- docker ps -a | grep $NAME &> /dev/null
- CONTAINER_EXISTS=$?
+ NAME="`basename "$toplevel"`_precommit"
- if [[ CONTAINER_EXISTS -eq 0 ]]; then
- docker restart $NAME && docker attach --no-stdin $NAME
+ if command -v podman > /dev/null 2>&1; then
+ container_exec=podman
+ elif command -v docker > /dev/null 2>&1; then
+ container_exec=docker
else
- docker run -t -v $(pwd):/pre-commit --name $NAME taghash/pre-commit
+ echo "No container executable found! Looked for \`podman' and \`docker'."
+ exit 1
fi
+ test -n "`"$container_exec" ps -a -q --no-trunc --filter 'name=^/?'"$NAME"'$'`"
+ CONTAINER_EXISTS=$?
+ if [ "$CONTAINER_EXISTS" -eq 0 ]; then
+ "$container_exec" restart "$NAME" && "$container_exec" attach --no-stdin "$NAME"
+ else
+ "$container_exec" run -t -v $(pwd):/pre-commit --name "$NAME" alexs77/pre-commit
+ fi
```
- Create an empty commit to test
- ```git commit --allow-empty -m "Test pre-commit"```
+ ```shell
+ git commit --allow-empty -m "Test pre-commit"
+ ```
# Note
- If you are going to use a `pre-commit` plugin that needs dependencies not packaged in this image, you can extend this image and install the dependencies you need
@@ -41,7 +53,5 @@
For example, if you add `{ id: detect-aws-credentials }` to `.pre-commit-config.yaml`, you have to mount the directory holding your aws credentials.
The docker command (as in the `pre-commit` script) would then become
```shell
- docker run -t -v $(pwd):/pre-commit -v $HOME/.aws:/root/.aws:ro --name $NAME taghash/pre-commit
+ "$container_exec" run -t -v $(pwd):/pre-commit -v $HOME/.aws:/root/.aws:ro --name $NAME alexs77/pre-commit
```
-
-
From 6b4238e9b130e6f15c0ce1eaee010ff6d6cb947e Mon Sep 17 00:00:00 2001
From: Alexander
Date: Thu, 17 Jun 2021 18:08:44 +0200
Subject: [PATCH 2/2] Use podman instead of docker executable
Look for podman as an exeuctable for running the container.
If not found, look for docker as well.
---
pre-commit | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/pre-commit b/pre-commit
index 67e0f23..b7e6bd4 100644
--- a/pre-commit
+++ b/pre-commit
@@ -1,11 +1,22 @@
-cd $(git rev-parse --show-toplevel)
+#!/bin/sh
+toplevel="`git rev-parse --show-toplevel`"
+cd "$toplevel"
-NAME=$(basename `git rev-parse --show-toplevel`)_precommit
-docker ps -a | grep nucleus_precommit &> /dev/null
+NAME="`basename "$toplevel"`_precommit"
+
+if command -v podman > /dev/null 2>&1; then
+ container_exec=podman
+elif command -v docker > /dev/null 2>&1; then
+ container_exec=docker
+else
+ echo "No container executable found! Looked for \`podman' and \`docker'."
+ exit 1
+fi
+test -n "`"$container_exec" ps -a -q --no-trunc --filter 'name=^/?'"$NAME"'$'`"
CONTAINER_EXISTS=$?
-if [[ CONTAINER_EXISTS -eq 0 ]]; then
- docker restart $NAME && docker attach --no-stdin $NAME
+if [ "$CONTAINER_EXISTS" -eq 0 ]; then
+ "$container_exec" restart "$NAME" && "$container_exec" attach --no-stdin "$NAME"
else
- docker run -t -v $(pwd):/pre-commit --name $NAME taghash/pre-commit
+ "$container_exec" run -t -v $(pwd):/pre-commit --name "$NAME" alexs77/pre-commit
fi