Skip to content

Commit 4fa795c

Browse files
committed
[BUGFIX] install.sh: Fix gsync not updating to latest when using branch
* improve _get_files_and_commits logic
1 parent 086e85b commit 4fa795c

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

install.sh

+14-6
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,24 @@ _get_files_and_commits() {
193193
# shellcheck disable=SC2086
194194
html_get_files_and_commits="$(curl -s --compressed "https://github.com/${repo_get_files_and_commits}/file-list/${type_value_get_files_and_commits}/${path_get_files_and_commits}")" ||
195195
{ _print_center "normal" "Error: Cannot fetch" " update details" "=" 1>&2 && exit 1; }
196+
# just grep the commit/ strings from html, then remove extra info with sed
196197
commits_get_files_and_commits="$(printf "%s\n" "${html_get_files_and_commits}" | grep -o "commit/.*\"" | sed -e 's/commit\///g' -e 's/\"//g' -e 's/>.*//g')"
198+
# only grep blob because we just want files
197199
# shellcheck disable=SC2001
198-
files_get_files_and_commits="$(printf "%s\n" "${html_get_files_and_commits}" | grep -oE '(blob|tree)/'"${type_value_get_files_and_commits}"'.*\"' | sed -e 's/\"//g' -e 's/>.*//g')"
200+
files_get_files_and_commits="$(printf "%s\n" "${html_get_files_and_commits}" | grep -oE 'blob/'"${type_value_get_files_and_commits}"'.*\"' | sed -e 's/\"//g' -e 's/>.*//g')"
199201

200202
total_files="$(($(printf "%s\n" "${files_get_files_and_commits}" | wc -l)))"
201203
total_commits="$(($(printf "%s\n" "${commits_get_files_and_commits}" | wc -l)))"
202-
if [ "$((total_files - 2))" -eq "${total_commits}" ]; then
203-
files_get_files_and_commits="$(printf "%s\n" "${files_get_files_and_commits}" | sed 1,2d)"
204-
elif [ "${total_files}" -gt "${total_commits}" ]; then
205-
files_get_files_and_commits="$(printf "%s\n" "${files_get_files_and_commits}" | sed 1d)"
204+
205+
# exit right out in case wasn't able to grab commits or files
206+
if [ "${total_commits}" -eq "0" ] || [ "${total_files}" -eq "0" ]; then
207+
_print_center "normal" "Error: Cannot fetch" " update details" "=" 1>&2 && exit 1
208+
fi
209+
210+
# this is gonna trigger in case of non-release commit sha
211+
if [ "${total_commits}" -gt "${total_files}" ]; then
212+
# delete alternate lines ( sed '{N;P;d}' ), because duplicate for every commit
213+
commits_get_files_and_commits="$(printf "%s\n" "${commits_get_files_and_commits}" | sed -e 'N;P;d')"
206214
fi
207215

208216
exec 4<< EOF
@@ -213,7 +221,7 @@ $(printf "%s\n" "${commits_get_files_and_commits}")
213221
EOF
214222
while read -r file <&4 && read -r commit <&5; do
215223
printf "%s\n" "${file##blob\/${type_value_get_files_and_commits}\/}__.__${commit}"
216-
done | grep -v tree || :
224+
done
217225
exec 4<&- && exec 5<&-
218226

219227
return 0

0 commit comments

Comments
 (0)