2021-03-01 01:40:43 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2022-04-21 01:22:55 +01:00
|
|
|
# Git REmote Make
|
2021-03-24 22:17:27 +00:00
|
|
|
# Push to SSH machine; build and scp build products back
|
2021-03-01 01:40:43 +00:00
|
|
|
|
|
|
|
set -e
|
2021-03-01 08:59:13 +00:00
|
|
|
git_branch=$(git branch --show-current)
|
2021-03-24 22:17:27 +00:00
|
|
|
# See https://unix.stackexchange.com/a/13472
|
|
|
|
remote_host=$(git remote get-url build | sed -nr -e "s/ssh:\/\/(\w+@?\w*):.*/\1/p") # Extract remote host
|
|
|
|
remote_path=$(git remote get-url build | sed -nr -e "s/ssh:\/\/\w+@?\w*://p") # Extract remote path
|
2022-04-21 01:22:55 +01:00
|
|
|
make_cmd=$(git config --local remake.make)
|
|
|
|
make_product=$(git config --local remake.src)
|
|
|
|
make_dest=$(git config --local remake.dest)
|
2024-01-26 03:40:00 +00:00
|
|
|
old_head=$(git rev-parse --short @)
|
|
|
|
set +e
|
|
|
|
# Make a temp commit for unstaged changes
|
|
|
|
temp_commit_msg="temp build"
|
|
|
|
git commit -aem "$temp_commit_msg"
|
|
|
|
retVal=$?
|
|
|
|
set -e
|
|
|
|
# set -x
|
2022-05-01 19:23:45 +01:00
|
|
|
git push build --force-with-lease
|
2024-01-26 03:40:00 +00:00
|
|
|
# { set +x; } 2>/dev/null
|
|
|
|
# Reset temp commit
|
|
|
|
if [[ $retVal -eq 0 ]]; then
|
|
|
|
commit_msg=$(git log -1 --pretty=%B)
|
|
|
|
if [[ "$commit_msg" == "$temp_commit_msg" ]]; then
|
2024-10-03 05:41:04 +01:00
|
|
|
# Keep i(N)tent to add
|
|
|
|
git reset --mixed -N "$old_head" &>/dev/null
|
2024-01-26 03:40:00 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
set -x
|
|
|
|
ssh -o "VisualHostKey=no" $remote_host "cd $remote_path && git reset --hard && git checkout $git_branch && $make_cmd"
|
|
|
|
scp -o "VisualHostKey=no" "$remote_host:$remote_path/$make_product" $make_dest
|