ia_dev/git-issues/create-branch-for-issue.sh
Nicolas Cantu e86a9fbb6e refactor: rename gitea-issues to git-issues and symlink projects to monorepo
- Rename directory and scripts env GIT_ISSUES_DIR; secrets path .secrets/git-issues
- Rename agent git-issues-process; update docs GIT_ISSUES_SCRIPTS_AGENTS.md
- Symlink projects/enso, smart_ide, builazoo to ../../projects/<id> when used inside smart_ide
- Update project conf paths for git-issues tokens and imap bridge
2026-04-03 19:05:28 +02:00

46 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Create a local branch for an issue. Branch name: issue/<number> (safe, short).
# Base branch defaults to "test"; ensure it is up to date (fetch + reset to origin/base).
# Usage: ./create-branch-for-issue.sh <issue_number> [base_branch]
#
set -euo pipefail
GIT_ISSUES_DIR="${GIT_ISSUES_DIR:-$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)}"
# shellcheck source=lib.sh
source "${GIT_ISSUES_DIR}/lib.sh"
if [[ $# -lt 1 ]]; then
log_err "Usage: $0 <issue_number> [base_branch]"
exit 1
fi
ISSUE_NUM="$1"
BASE="${2:-test}"
require_git_root || exit 1
if git show-ref --quiet "refs/heads/issue/${ISSUE_NUM}"; then
log_info "Branch issue/${ISSUE_NUM} already exists. Checking it out."
git checkout "issue/${ISSUE_NUM}"
echo "issue/${ISSUE_NUM}"
exit 0
fi
if ! git show-ref --quiet "refs/heads/${BASE}"; then
log_err "Base branch ${BASE} does not exist locally."
exit 1
fi
git fetch origin
if git show-ref --quiet "refs/remotes/origin/${BASE}"; then
git checkout "${BASE}"
git reset --hard "origin/${BASE}"
else
git checkout "${BASE}"
fi
git checkout -b "issue/${ISSUE_NUM}"
log_info "Created and checked out branch issue/${ISSUE_NUM} from ${BASE}."
echo "issue/${ISSUE_NUM}"