Created
July 4, 2020 14:27
-
-
Save nauar/e5e6c7aaa8fd83c0df0d0202f7124fa6 to your computer and use it in GitHub Desktop.
Bash script for looking for a tag in a remote git repository
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # This script is used for searching a tag in git. Parameters: | |
| # | |
| # GIT_REPO: Repository URL | |
| # GIT_TAG: Tag to look for | |
| GITCMD="git" | |
| function log() { | |
| moment=`date '+%d/%m/%Y %H:%M:%S'` | |
| echo "[ $moment ] [ TAG_SEARCH ] $1" | |
| } | |
| function search() { | |
| GIT_REPO=$1 | |
| GIT_TAG=$2 | |
| log "Looking if tag ${GIT_TAG} exists in repo ${GIT_REPO}..." | |
| exists=$($GITCMD ls-remote --tags --refs ${GIT_REPO} | awk '{ print $2;}' | sed 's/refs\/tags\///g' | grep "^${GIT_TAG}$" | wc -l) | |
| if [ "$exists" -eq "1" ]; then | |
| log "Tag ${GIT_TAG} found in repo ${GIT_REPO}" | |
| return 1 | |
| else | |
| log "Tag ${GIT_TAG} not found in repo ${GIT_REPO}" | |
| return 0 | |
| fi | |
| } | |
| search $1 $2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment