updating with tested methods
This commit is contained in:
parent
db11d6a432
commit
b97b438c52
@ -5,25 +5,35 @@ If you want to add a git hash or version to an environment file, such as in a La
|
||||
Filename: `.git/hooks/post-commit`
|
||||
|
||||
```
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Redirect output to stderr.
|
||||
exec 1>&2
|
||||
|
||||
GIT_HASH=$(git rev-parse --short HEAD)
|
||||
echo "Applying the following hash: $GIT_HASH"
|
||||
sed -i "/APP_GIT_HASH/c\APP_GIT_HASH=\"${GIT_HASH}\"" .env
|
||||
SHORT_HASH=$(git rev-parse --short HEAD)
|
||||
sed -i "/^GIT_HASH=\".*\"/ s//GIT_HASH=\"${SHORT_HASH}\"/" .env
|
||||
```
|
||||
|
||||
If you would like to have which branch/tag you are using written to the environment file every time you checkout a new branch/tag, you can use this:
|
||||
If you would like to have which branch you are using written to the environment file every time you checkout a new branch, you can use this:
|
||||
|
||||
```
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Redirect output to stderr.
|
||||
exec 1>&2
|
||||
|
||||
GIT_BRANCH=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)
|
||||
echo "Applying the following hash: $GIT_BRANCH"
|
||||
sed -i "/APP_VERSION/c\APP_VERSION=\"${GIT_BRANCH}\"" .env
|
||||
GIT_BRANCH=$(git branch --show-current)
|
||||
if [ -n "$GIT_BRANCH" ]; then
|
||||
sed -i "/^GIT_BRANCH=\".*\"/ s//GIT_BRANCH=\"${GIT_BRANCH}\"/" .env
|
||||
else
|
||||
sed -i "/^GIT_BRANCH=\".*\"/ s//GIT_BRANCH=\"\"/" .env
|
||||
fi
|
||||
```
|
||||
|
||||
If you would also like to have the git tag written to the environment file, you can use this:
|
||||
|
||||
```
|
||||
#!/usr/bin/env bash
|
||||
|
||||
GIT_TAG=$(git tag --points-at HEAD)
|
||||
#GIT_TAG=$(git describe --exact-match --tags --abbrev=0 2>&1) # alternative way of getting the tag, potentially less stable
|
||||
if [ -n "$GIT_TAG" ]; then
|
||||
sed -i "/^GIT_TAG=\".*\"/ s//GIT_TAG=\"${GIT_TAG}\"/" .env
|
||||
else
|
||||
sed -i "/^GIT_TAG=\".*\"/ s//GIT_TAG=\"\"/" .env
|
||||
fi
|
||||
```
|
||||
|
17
hooks/local/post-checkout
Normal file
17
hooks/local/post-checkout
Normal file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
GIT_TAG=$(git tag --points-at HEAD)
|
||||
#GIT_TAG=$(git describe --exact-match --tags --abbrev=0 2>&1) # alternative way of getting the tag, potentially less stable
|
||||
if [ -n "$GIT_TAG" ]; then
|
||||
sed -i "/^GIT_TAG=\".*\"/ s//GIT_TAG=\"${GIT_TAG}\"/" .env
|
||||
else
|
||||
sed -i "/^GIT_TAG=\".*\"/ s//GIT_TAG=\"\"/" .env
|
||||
fi
|
||||
|
||||
#GIT_BRANCH=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match)
|
||||
GIT_BRANCH=$(git branch --show-current)
|
||||
if [ -n "$GIT_BRANCH" ]; then
|
||||
sed -i "/^GIT_BRANCH=\".*\"/ s//GIT_BRANCH=\"${GIT_BRANCH}\"/" .env
|
||||
else
|
||||
sed -i "/^GIT_BRANCH=\".*\"/ s//GIT_BRANCH=\"\"/" .env
|
||||
fi
|
4
hooks/local/post-commit
Normal file
4
hooks/local/post-commit
Normal file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
SHORT_HASH=$(git rev-parse --short HEAD)
|
||||
sed -i "/^GIT_HASH=\".*\"/ s//GIT_HASH=\"${SHORT_HASH}\"/" .env
|
Loading…
x
Reference in New Issue
Block a user