summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2019-09-15 07:14:41 -0400
committerAndrew Cady <d@jerkface.net>2019-09-15 07:14:41 -0400
commit2165741a249ce1dc3df5fdb8cae6f0c5522588f7 (patch)
tree680c35b0d3013834b174a69f29febc59f71b3555
initial commit
-rwxr-xr-xyamlremote90
1 files changed, 90 insertions, 0 deletions
diff --git a/yamlremote b/yamlremote
new file mode 100755
index 0000000..c102003
--- /dev/null
+++ b/yamlremote
@@ -0,0 +1,90 @@
1#!/bin/sh
2extra_dep=y
3keep_orig_line=y
4
5main()
6{
7 if [ $# = 0 ]; then
8 while read line; do
9 set -- $line
10 while [ "$1" = - ]
11 do
12 shift
13 done
14 (generate_yaml_remote "$1" "$line")
15 done
16 else
17 for a; do (generate_yaml_remote "$a" "- $a"); done
18 fi
19}
20
21# Example output:
22#
23# - location:
24# git: https://github.com/bitemyapp/esqueleto.git
25# commit: 08c9b4cdf977d5bcd1baba046a007940c1940758
26# extra-dep: true
27#
28# And with subdirs:
29#
30# - location:
31# git: d@emmy.childrenofmay.org:public_git/lambdacube-ir
32# commit: f6617496f582ad287bd8203d931a6ee037ed3a69
33# subdirs:
34# - lambdacube-ir.haskell
35# - ddl
36# extra-dep: true
37
38# cat, except drop empty lines
39cat_()
40{
41 sed -e '/^$/d'
42}
43
44output()
45{
46 local git_url="$1" git_hash="$2" subdir="$3" orig_line="$4"
47 case "$git_url" in
48 *@*) ;;
49 *) git_url=$(id -un)@$git_url ;;
50 esac
51 cat_ <<EOF
52${keep_orig_line:+
53# $orig_line}
54- location:
55 git: $git_url
56 commit: $git_hash
57${subdir:+
58 subdirs:
59 - $subdir}
60${extra_dep:+
61 extra-dep: true}
62EOF
63}
64
65generate_yaml_remote()
66{
67 set -e
68 orig_line=$2
69 cd "$1"
70 git_toplevel=$(git rev-parse --show-toplevel)
71 if [ "$git_toplevel" != "$PWD" ]
72 then
73 subdir=${PWD#$git_toplevel/}
74 fi
75
76 local_ref=$(git rev-parse --abbrev-ref HEAD)
77 remote_ref=$(git show-ref $local_ref | grep ' refs/remotes/' | head -n1)
78
79 set -- $remote_ref
80 sha1=$1
81 ref=$2
82
83 remote=${ref%/*}
84 remote=${remote#refs/remotes/}
85 url=$(git remote get-url $remote)
86
87 output "$url" "$sha1" "$subdir" "$orig_line"
88}
89
90main "$@"