#!/bin/bash

set -exx

eval `git grep -h SRCVERSION rpm/config.sh`

test -z "$SRCVERSION" && exit 1

VER="$SRCVERSION"
FORCE=
RC=""
while getopts "fr" OPT; do
        case "$OPT" in
        f) FORCE=1 ;;
        r) RC="-rc" ;;
        esac
done

TREE="stable${RC}/linux-$VER.y"

VER=`{ git -C "$LINUX_GIT" show "$TREE":Makefile | head -4;
	echo -e 'ver:\n\t@echo $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)'
	} | make -f - ver`

if [ -n "$RC" ]; then
	git -C "$LINUX_GIT" tag "v$VER" "$TREE"
	trap "git -C "$LINUX_GIT" tag -d \"v$VER\"" EXIT
fi

./scripts/stableup "$VER" $FORCE
