-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgit-backtag
executable file
·62 lines (51 loc) · 1.13 KB
/
git-backtag
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env bash
#
# A custom git command that implements backdating tags as described in
# https://git-scm.com/docs/git-tag#_on_backdating_tags .
#
# Author: Lucas Magasweran <[email protected]>
#
set -o errexit
usage() {
echo "usage: git backtag [-h|-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> <commit>"
echo -e " commit date of commit will be used to backdate tag"
}
opts=`getopt --options hasfu:m:F: --long annotate,sign,force,local-user:,message:,file: -- "$@"`
if [ $? != 0 ] ; then echo "Failed parsing options." >&2 ; exit 1 ; fi
eval set -- "$opts"
while [[ $# != 0 ]]; do
case "$1" in
-h)
usage
exit
;;
-a|--annotate) ;&
-s|--sign) ;&
-f|--force)
shift
;;
-u|--local-user) ;&
-m|--message) ;&
-F|--file)
shift 2
;;
--)
shift
break
;;
esac
done
if [[ -z ${1} ]] || [[ -z ${2} ]]; then
usage
exit 1
fi
tagname=$1
commit=$2
branch=$(git symbolic-ref --short -q HEAD)
remove_commit() {
echo "${@:1:$#-1}"
}
opts2=`remove_commit ${opts}`
git checkout --quiet $commit
GIT_COMMITTER_DATE="$(git show --format=%aD | head -1)" eval git tag ${opts2}
git checkout --quiet $branch