contrib: git-c2t converts tag creating commits to tags
[git/mjg.git] / contrib / git-c2t.sh
blob14c9bf0a49eb8e92ead29784d83e6c007e1159c6
1 #!/bin/sh
3 die () {
4 echo "$@"
5 rm -f "$tagfile"
6 exit 1
9 warn () {
10 echo "$@"
13 test $# -eq 2 || die "Usage: $0 <commit> <tagname>"
15 tagname="$2"
16 commit="$1"
18 git rev-parse --verify -q "$commit" >/dev/null || die "Cannot parse $commit."
20 test x$(git cat-file -t $commit) == "xcommit" || die "$commit is no commit."
22 tagfile=$(mktemp)
24 git cat-file commit "$commit" | {
25 read drop tree
26 test $drop == "tree" || die "No tree."
27 read drop parent
28 test $drop = "parent" || die "No parent."
29 read drop author
30 test $drop == "author" || die "No author."
31 read drop committer
32 test $drop == "committer" || die "No committer."
33 test "$author" == "$committer" || warn "author $author != committer $committer, taking author."
34 ptree=$(git cat-file -p $parent|fgrep tree|head -1|cut -d' ' -f2)
35 test $ptree == $tree || die "commit $commit introduces a diff."
36 cat <<EOF >$tagfile
37 object $parent
38 type commit
39 tag $tagname
40 tagger $author
41 EOF
42 cat >>$tagfile
43 hash=$(git hash-object -t tag -w "$tagfile")
44 git tag "$tagname" $hash
46 rm -f $tagfile