2020-09-08 18:38:11 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
2020-09-08 18:53:10 +02:00
|
|
|
find_last_commit_for_title() {
|
|
|
|
local title="$1"
|
|
|
|
git log --oneline --author=SpiritCroc | grep "$title" | head -n 1 | sed 's| .*||'
|
|
|
|
}
|
|
|
|
|
|
|
|
revert_last() {
|
|
|
|
local title="$1"
|
2020-12-15 16:05:43 +01:00
|
|
|
shift
|
|
|
|
git revert --no-edit `find_last_commit_for_title "$title"` $@
|
2020-09-08 18:53:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
require_clean_git() {
|
2020-11-05 16:46:32 +01:00
|
|
|
if [ "$NO_REQUIRE_CLEAN_GIT" = "y" ]; then
|
|
|
|
return
|
|
|
|
fi
|
2020-09-08 18:53:10 +02:00
|
|
|
uncommitted=`git status --porcelain`
|
|
|
|
if [ ! -z "$uncommitted" ]; then
|
|
|
|
echo "Uncommitted changes are present, please commit first!"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2020-09-08 18:38:11 +02:00
|
|
|
upstream_latest_tag() {
|
2020-09-10 11:11:01 +02:00
|
|
|
git describe --abbrev=0 upstream/master --tags
|
2020-09-08 18:38:11 +02:00
|
|
|
}
|
|
|
|
upstream_previous_tag() {
|
2020-12-12 14:09:49 +01:00
|
|
|
#git describe --abbrev=0 `upstream_latest_tag`~1 --tags
|
2021-04-09 11:48:29 +02:00
|
|
|
#downstream_latest_tag | sed 's|sc_\(v.*\).sc.*|\1|'
|
|
|
|
git log | grep "Merge tag 'v.*' into sc" | head -n 1 |sed "s|Merge tag '\\(v.*\\)' into sc|\1|"
|
2020-09-08 18:38:11 +02:00
|
|
|
}
|
2020-09-08 18:53:10 +02:00
|
|
|
downstream_latest_tag() {
|
2020-11-06 14:17:56 +01:00
|
|
|
local commit="HEAD"
|
2020-09-10 11:11:01 +02:00
|
|
|
while true; do
|
|
|
|
local tag=`git describe --abbrev=0 "$commit" --tags`
|
|
|
|
if [[ "$tag" =~ "sc_" ]]; then
|
|
|
|
echo "$tag"
|
|
|
|
break
|
|
|
|
else
|
|
|
|
commit="$commit^1"
|
|
|
|
fi
|
|
|
|
done
|
2020-09-08 18:53:10 +02:00
|
|
|
}
|
|
|
|
|
2020-09-08 18:38:11 +02:00
|
|
|
upstream_diff() {
|
|
|
|
local latest_tag=`upstream_latest_tag`
|
|
|
|
local previous_tag=`upstream_previous_tag`
|
|
|
|
git diff "$previous_tag".."$latest_tag" "$@"
|
|
|
|
}
|
2020-09-27 13:57:46 +02:00
|
|
|
upstream_log() {
|
|
|
|
local latest_tag=`upstream_latest_tag`
|
|
|
|
local previous_tag=`upstream_previous_tag`
|
|
|
|
git log "$previous_tag".."$latest_tag" "$@"
|
|
|
|
}
|
2020-09-08 18:53:10 +02:00
|
|
|
|
|
|
|
downstream_upstream_diff() {
|
|
|
|
local previous_tag=`upstream_previous_tag`
|
|
|
|
local downstream_tag=`downstream_latest_tag`
|
|
|
|
git diff "$previous_tag".."$downstream_latest_tag" "$@"
|
|
|
|
}
|
2020-12-22 09:15:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Opposite to restore_sc
|
|
|
|
restore_upstream() {
|
|
|
|
local f="$(basename "$1")"
|
|
|
|
local path="$(dirname "$1")"
|
|
|
|
local sc_f="tmp_sc_$f"
|
|
|
|
local upstream_f="upstream_$f"
|
|
|
|
mv "$path/$f" "$path/$sc_f"
|
|
|
|
if [ -e "$path/$upstream_f" ]; then
|
|
|
|
mv "$path/$upstream_f" "$path/$f"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Oposite to restore_upstream
|
|
|
|
restore_sc() {
|
|
|
|
local f="$(basename "$1")"
|
|
|
|
local path="$(dirname "$1")"
|
|
|
|
local sc_f="tmp_sc_$f"
|
|
|
|
local upstream_f="upstream_$f"
|
|
|
|
if [ -e "$path/$f" ]; then
|
|
|
|
mv "$path/$f" "$path/$upstream_f"
|
|
|
|
fi
|
|
|
|
if [ -e "$path/$sc_f" ]; then
|
|
|
|
mv "$path/$sc_f" "$path/$f"
|
|
|
|
fi
|
|
|
|
}
|
2021-02-20 15:43:51 +01:00
|
|
|
|
|
|
|
await_edit() {
|
|
|
|
local f="$1"
|
|
|
|
shift 1
|
|
|
|
if [ ! -z "$GRAPHICAL_EDITOR" ]; then
|
|
|
|
$GRAPHICAL_EDITOR "$f"
|
|
|
|
read -p "Press enter when done"
|
|
|
|
elif [ ! -z "$VISUAL" ]; then
|
|
|
|
$VISUAL "$f"
|
|
|
|
elif [ ! -z "$EDITOR" ]; then
|
|
|
|
$EDITOR "$f"
|
|
|
|
else
|
|
|
|
read -p "No editor set, please edit $f manually, and press enter when done"
|
|
|
|
fi
|
|
|
|
}
|