Do not create tag if it was created on same commit as current branch#10
Do not create tag if it was created on same commit as current branch#10pionl wants to merge 1 commit into
Conversation
|
thanks for the contribution! I'll test it out |
| LAST_TAG=$(git describe --abbrev=0 --tags 2>/dev/null) | ||
|
|
||
| # Ensure that tag is not created on same commit as current branch commit | ||
| if [[ ! -z "$LAST_TAG" ]]; then |
There was a problem hiding this comment.
It's more elegant to use the not empty check than to check if filled and negate
| if [[ ! -z "$LAST_TAG" ]]; then | |
| if [[ -n "$LAST_TAG" ]]; then |
|
|
||
| if [[ "$BRANCH_HASH" = "$LAST_TAG_HASH" ]]; then | ||
| echo "Last tag is on the same commit as current branch"; | ||
| exit 0; |
There was a problem hiding this comment.
Rather make it an error.
| exit 0; | |
| exit 1 |
| # Ensure that tag is not created on same commit as current branch commit | ||
| if [[ ! -z "$LAST_TAG" ]]; then | ||
| CURRENT_BRANCH=$(git branch --show-current) | ||
| BRANCH_HASH=$(git rev-list -n 1 $CURRENT_BRANCH) |
There was a problem hiding this comment.
If you use rev-parse it already gets one commit so you don't have to set it.
https://michaelcurrin.github.io/dev-cheatsheets/cheatsheets/version-control/git/advanced.html
And if you use HEAD, that already points to the current commit. No branch name needed.
| BRANCH_HASH=$(git rev-list -n 1 $CURRENT_BRANCH) | |
| BRANCH_HASH=$(git rev-parse HEAD) |
| if [[ ! -z "$LAST_TAG" ]]; then | ||
| CURRENT_BRANCH=$(git branch --show-current) | ||
| BRANCH_HASH=$(git rev-list -n 1 $CURRENT_BRANCH) | ||
| LAST_TAG_HASH=$(git rev-list -n 1 $LAST_TAG) |
There was a problem hiding this comment.
| LAST_TAG_HASH=$(git rev-list -n 1 $LAST_TAG) | |
| LAST_TAG_HASH=$(git rev-parse $LAST_TAG) |
|
|
||
| # Ensure that tag is not created on same commit as current branch commit | ||
| if [[ ! -z "$LAST_TAG" ]]; then | ||
| CURRENT_BRANCH=$(git branch --show-current) |
There was a problem hiding this comment.
No longer needed. See below.
| CURRENT_BRANCH=$(git branch --show-current) |
| BRANCH_HASH=$(git rev-list -n 1 $CURRENT_BRANCH) | ||
| LAST_TAG_HASH=$(git rev-list -n 1 $LAST_TAG) | ||
|
|
||
| if [[ "$BRANCH_HASH" = "$LAST_TAG_HASH" ]]; then |
There was a problem hiding this comment.
I've used double equals elsewhere in the script, so remain consistent with that. Same behavior though.
| if [[ "$BRANCH_HASH" = "$LAST_TAG_HASH" ]]; then | |
| if [[ "$BRANCH_HASH" == "$LAST_TAG_HASH" ]]; then |
|
|
||
| LAST_TAG=$(git describe --abbrev=0 --tags 2>/dev/null) | ||
|
|
||
| # Ensure that tag is not created on same commit as current branch commit |
There was a problem hiding this comment.
| # Ensure that tag is not created on same commit as current branch commit | |
| # Check if the current commit is already tagged. |
| LAST_TAG_HASH=$(git rev-list -n 1 $LAST_TAG) | ||
|
|
||
| if [[ "$BRANCH_HASH" = "$LAST_TAG_HASH" ]]; then | ||
| echo "Last tag is on the same commit as current branch"; |
There was a problem hiding this comment.
That's quiet a mouthful. Just say the thing that we are watching out for and alert on it.
| echo "Last tag is on the same commit as current branch"; | |
| echo "The current commit already has a commit on it. Aborting, to avoid tagging it again." |
Trailing semi-colons are superfluous here. Got JavaScript / Java on the brain?
|
I made some refactor suggestions, so that you can learn more about the shell and git. But closing this PR because of alternative covered below. |
|
A more elegant solution is to use git's built-in check for whether a commit is tagged or not. Try this out in your terminal. git describe --tags --exact-match HEAD &> /dev/null \
&& echo 'Commit is tagged' \
|| echo 'Commit is NOT tagged'Thanks to And then that can be adapted. I've made PR #11 as a shorter form and replacement of what you are doing here. I'd appreciate your review of that please. |
Hi, thanks for the great script! Before I've checked the issue I wanted this feature too.
I've tried on clean repo, made changes, etc..
Resolves #3