Files
workdock-platform/scripts/git_remote_target.sh
2026-04-01 13:52:55 +02:00

117 lines
3.0 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO_ROOT"
TUBCO_NAME="bostame"
TUBCO_EMAIL="mdbayazid@tub.co"
usage() {
cat <<'EOF'
Usage:
./scripts/git_remote_target.sh status
./scripts/git_remote_target.sh push-origin [ref]
./scripts/git_remote_target.sh push-tubco [ref]
./scripts/git_remote_target.sh set-own-identity
./scripts/git_remote_target.sh set-tubco-identity
Commands:
status
Show current branch, current commit, active local git identity, configured remotes,
and the local push-safety settings.
push-origin [ref]
Push a ref to the main product remote "origin".
Default ref: current branch
push-tubco [ref]
Push a ref to the TUBCO customer remote "tubco".
Default ref: release/tubco-v1
set-own-identity
Remove the repo-local git user.name and user.email so this repo falls back to your normal identity.
set-tubco-identity
Set the repo-local git identity to the TUBCO customer identity.
EOF
}
require_remote() {
local remote="$1"
git remote get-url "$remote" >/dev/null 2>&1 || {
echo "Missing git remote: $remote" >&2
exit 1
}
}
current_branch() {
git branch --show-current
}
show_identity() {
local local_name local_email
local_name="$(git config --local --get user.name || true)"
local_email="$(git config --local --get user.email || true)"
if [[ -n "$local_name" || -n "$local_email" ]]; then
echo "Local repo identity: ${local_name:-<unset>} <${local_email:-unset}>"
else
echo "Local repo identity: not set in this repo (falls back to global/default git config)"
fi
}
show_push_safety() {
local push_default hooks_path
push_default="$(git config --local --get remote.pushDefault || true)"
hooks_path="$(git config --local --get core.hooksPath || true)"
echo "remote.pushDefault: ${push_default:-<unset>}"
echo "core.hooksPath: ${hooks_path:-<unset>}"
}
case "${1:-}" in
status)
echo "Branch: $(current_branch)"
echo "Commit: $(git rev-parse --short HEAD)"
show_identity
show_push_safety
echo
echo "Remotes:"
git remote -v
echo
echo "Recommended targets:"
echo " develop/main/internal work -> origin"
echo " release/tubco-v1 and approved customer backports -> tubco"
;;
push-origin)
require_remote origin
ref="${2:-$(current_branch)}"
echo "Pushing '$ref' to origin..."
git push origin "$ref"
;;
push-tubco)
require_remote tubco
ref="${2:-release/tubco-v1}"
echo "Pushing '$ref' to tubco..."
git push tubco "$ref"
;;
set-own-identity)
git config --local --unset-all user.name >/dev/null 2>&1 || true
git config --local --unset-all user.email >/dev/null 2>&1 || true
echo "Cleared repo-local git identity. This repo will now use your normal git identity."
;;
set-tubco-identity)
git config --local user.name "$TUBCO_NAME"
git config --local user.email "$TUBCO_EMAIL"
echo "Set repo-local git identity to: $TUBCO_NAME <$TUBCO_EMAIL>"
;;
*)
usage
exit 1
;;
esac