aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xfetch_version49
1 files changed, 42 insertions, 7 deletions
diff --git a/fetch_version b/fetch_version
index cbbeb64..492aff1 100755
--- a/fetch_version
+++ b/fetch_version
@@ -2,7 +2,7 @@
2 2
3usage() { 3usage() {
4 echo "$0 file.json" 4 echo "$0 file.json"
5 echo "$0 [-n|--name name] [-b|--branch branch] [-f|--file out_file] [-h|--help] (-u|--url) url" 5 echo "$0 [-n|--name name] [-b|--branch branch_or_rev] [-f|--file out_file] [-h|--help] (-u|--url) url"
6 exit 6 exit
7} 7}
8 8
@@ -72,18 +72,53 @@ fi
72# printf com ? "%s-%s-g%s\n" : "%s\n", tag, com, sha 72# printf com ? "%s-%s-g%s\n" : "%s\n", tag, com, sha
73# }' 73# }'
74 74
75function get_ref () {
76 case "$1" in
77 refs/*)
78 echo "$1"
79 ;;
80 *)
81 echo "refs/heads/$1"
82 ;;
83 esac
84}
85
86function get_name () {
87 branch="$1"
88 rev="$2"
89 minirev=${rev:0:7}
90
91 case "$branch" in
92 refs/tags/*)
93 b="${branch#refs/tags/}"
94 echo "${b//\//-}"
95 ;;
96 refs/heads/*)
97 b=${branch#refs/heads/}
98 echo "$minirev-${b//\//-}"
99 ;;
100 refs/*)
101 b=${branch#refs/}
102 echo "$minirev-${b//\//-}"
103 ;;
104 *)
105 echo "$minirev-${branch//\//-}"
106 ;;
107 esac
108}
109
75function fetch_github () { 110function fetch_github () {
76 rev="$(git ls-remote --refs $url refs/heads/$branch | head -n1 | cut -f1)" 111 rev="$(git ls-remote --refs $url $(get_ref $branch) | head -n1 | cut -f1)"
77 sha="$(nix-prefetch-url --unpack $url/archive/$branch.tar.gz)" 112 sha="$(nix-prefetch-url --unpack $url/archive/$rev.tar.gz)"
78 # Différent du git-describe et github-spécifique 113 # Différent du git-describe et github-spécifique
79 #tag=$(echo "$awk_describe" | awk -f - $url | sed -e "s/^v//") 114 #tag=$(echo "$awk_describe" | awk -f - $url | sed -e "s/^v//")
80 tag=${rev:0:7}-$branch 115 tag=$(get_name $branch $rev)
81} 116}
82 117
83function fetch_other () { 118function fetch_other () {
84 rev="$(git ls-remote --refs $url refs/heads/$branch | head -n1 | cut -f1)" 119 rev="$(git ls-remote --refs $url $(get_ref $branch) | head -n1 | cut -f1)"
85 sha="$(nix-prefetch-git --url $url --rev refs/heads/$branch | jq -r '.sha256')" 120 sha="$(nix-prefetch-git --url $url --rev $(get_ref $branch) | jq -r '.sha256')"
86 tag=${rev:0:7}-$branch 121 tag=$(get_name $branch $rev)
87} 122}
88 123
89case "$url" in 124case "$url" in