#!/usr/bin/env fish # # Update git-subtree-vendored repositories listed in vendor/sources. # # vendor/sources format (tab-separated): # name url branch # # Lines starting with # are ignored. # # Usage: # scripts/vendor-update.fish # update all vendored repos # scripts/vendor-update.fish forge # update only vendor/forge set repo_root (git -C (status dirname) rev-parse --show-toplevel) if test $status -ne 0 echo "error: not inside a git repository" >&2 exit 1 end cd $repo_root set sources_file vendor/sources if not test -f $sources_file echo "error: $sources_file not found" >&2 exit 1 end set filter $argv set failed 0 set found 0 while read -l line # Skip comments and blank lines string match -qr '^\s*#' -- $line; and continue string match -qr '^\s*$' -- $line; and continue set parts (string split \t -- $line) if test (count $parts) -ne 3 echo "skip: malformed line: $line" >&2 set failed (math $failed + 1) continue end set name $parts[1] set url $parts[2] set branch $parts[3] # If specific targets were given, skip non-matching entries if test (count $filter) -gt 0 contains $name $filter; or continue end set found (math $found + 1) if not test -d vendor/$name echo "skip: vendor/$name does not exist (run 'git subtree add' first)" >&2 set failed (math $failed + 1) continue end echo ":: updating vendor/$name from $url ($branch)" git subtree pull --prefix=vendor/$name $url $branch --squash if test $status -ne 0 echo "error: failed to update vendor/$name" >&2 set failed (math $failed + 1) else echo ":: vendor/$name updated" end echo end <$sources_file if test $found -eq 0 echo "No matching vendored repos found." >&2 exit 1 end if test $failed -gt 0 echo "$failed vendor update(s) failed" >&2 exit 1 end