2016-07-21 13:48:49 +00:00
|
|
|
#!/bin/bash
|
2019-07-26 13:19:33 +00:00
|
|
|
set -euo pipefail
|
2017-07-17 09:55:39 +00:00
|
|
|
|
2017-09-19 10:10:53 +00:00
|
|
|
source "${HOME}/bin/script_framework.sh"
|
2016-07-21 13:48:49 +00:00
|
|
|
|
2019-07-26 13:19:33 +00:00
|
|
|
jump_branch="${1:-}"
|
|
|
|
|
2017-08-08 09:56:36 +00:00
|
|
|
step "Loading required keys to pull"
|
|
|
|
git loadkey
|
|
|
|
|
2016-07-21 13:48:49 +00:00
|
|
|
step "Fetching data from remote..."
|
|
|
|
for remote in $(git remote -v | awk '{print $1}' | sort | uniq); do
|
2019-07-26 13:19:33 +00:00
|
|
|
step "+++ Remote: '${remote}'"
|
|
|
|
git fetch -p ${remote} --tags
|
2016-07-21 13:48:49 +00:00
|
|
|
done
|
|
|
|
|
2019-07-26 13:19:33 +00:00
|
|
|
[[ -z ${jump_branch} ]] || {
|
|
|
|
step "Switching to branch ${jump_branch}"
|
2020-08-04 09:12:42 +00:00
|
|
|
git switch "${jump_branch}"
|
2019-07-26 13:19:33 +00:00
|
|
|
}
|
|
|
|
|
2016-07-21 13:48:49 +00:00
|
|
|
step "Rebasing branch / updating submodules..."
|
|
|
|
git pull --rebase && git submodule update --init --recursive
|
|
|
|
|
|
|
|
step "Cleaning local branches..."
|
|
|
|
for branch in $(git branch --merged | grep -v '^*'); do
|
2019-07-26 13:19:33 +00:00
|
|
|
# Do not delete master as the main branch
|
|
|
|
if (test "${branch}" != "master"); then
|
|
|
|
git branch -d ${branch}
|
|
|
|
fi
|
2016-07-21 13:48:49 +00:00
|
|
|
done
|
2016-10-24 06:16:23 +00:00
|
|
|
|
|
|
|
step "Removing local branches where remote branch is gone..."
|
2018-03-10 11:47:55 +00:00
|
|
|
if (git branch -vv | grep -q ': gone]'); then
|
2019-07-26 13:19:33 +00:00
|
|
|
git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D
|
2016-10-24 06:20:44 +00:00
|
|
|
fi
|