-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit_identifier.sh
More file actions
executable file
·74 lines (57 loc) · 1.98 KB
/
git_identifier.sh
File metadata and controls
executable file
·74 lines (57 loc) · 1.98 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash
git_identifier_usage(){ cat << EOU
Provide an identifier string for a git repository
===================================================
This script expects to be kept at the top level of a git repository.
::
./git_identifier.sh
./git_identifier.sh NOTE
A[blyth@localhost j]$ ./git_identifier.sh
j_notag_9685c51_20250423103025
A[blyth@localhost j]$ ./git_identifier.sh NOTE
uncommitted changes in working copy : so include timestamp in identifier
A[blyth@localhost opticks]$ ./git_identifier.sh
opticks_v0.3.8_8ef31c325_20250423103326
A[blyth@localhost opticks]$ ./git_identifier.sh NOTE
uncommitted changes in working copy : so include timestamp in identifier
EOU
}
git_identifier()
{
local arg=$1
local ltag=$(git tag | tail -1)
local ltaghash
if [ "$ltag" == "" ]; then
ltag="notag"
ltaghash="placeholder"
else
ltaghash=$(git rev-parse --short ${ltag}^{})
fi
local headhash=$(git rev-parse --short HEAD)
local porcelain=$(git status --porcelain)
local timestamp=$(date +"%Y%m%d%H%M%S")
local pfx=$(basename $PWD)
local identifier
local note
if [ "$porcelain" != "" ]; then
note="uncommitted changes in working copy : so include timestamp in identifier"
identifier=${pfx}_${ltag}_${headhash}_${timestamp}
else
if [ "$ltaghash" == "$headhash" ]; then
note="no uncommited changes and HEAD repo commit matches the last tag hash : so identify with last tag"
identifier=${pfx}_$ltag
else
note="no uncommitted changes but there have been commits since the last tag : so identify with last tag and HEAD commit hash"
identifier=${pfx}_${ltag}_${headhash}
fi
fi
case $arg in
IDENTIFIER) echo $identifier ;;
NOTE) echo $note ;;
TIME) echo $timestamp ;;
esac
return 0
}
cd $(dirname $(realpath $BASH_SOURCE))
arg=${1:-IDENTIFIER}
git_identifier $arg