-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrewrite.sh
executable file
·51 lines (39 loc) · 1.16 KB
/
rewrite.sh
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
#!/bin/bash
set -e
set -u
INFILE=$1
OUTFILE=$2
TYPE=${3:-UNKNOWN}
echo "# Environment type: ${TYPE}" > ${OUTFILE}
echo "# Created on $(date) by ${USER}@$(hostname)" >> ${OUTFILE}
for item in $(cat ${INFILE}); do
echo -n '.'
if egrep -q "^git\+https" <<< $item > /dev/null 2>&1; then
unset path_items
unset branch_items
declare -a path_items
declare -a branch_items
path=${item/#git+/}
path_items=( ${path/@/ } )
repo=${path_items[0]}
branch_items=( ${path_items[1]/\#/ } )
branch=${branch_items[0]}
rest=${branch_items[1]}
if [ ${#branch} -eq 40 ]; then
shainfo="as specified"
sha=${branch}
else
unset sha_info
declare -a sha_info
sha_info=( $(git ls-remote ${repo} | egrep "refs/[^/]*/${branch}$") )
sha=${sha_info[0]}
shainfo=${sha_info[1]}
fi
echo -e "\n# ${item}" >> ${OUTFILE}
echo "# Using sha ${sha} (${shainfo})" >> ${OUTFILE}
echo "git+${repo}@${sha}#${rest}" >> ${OUTFILE}
else
echo "${item}" >> ${OUTFILE}
fi
done
echo