Merge pull request 'fix: bug: migrate_ops_repo emits fatal: not in a git directory mid-migration, silently skipping commit/push (#587)' (#627) from fix/issue-587 into main
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
All checks were successful
ci/woodpecker/push/ci Pipeline was successful
This commit is contained in:
commit
506a00151b
1 changed files with 42 additions and 28 deletions
|
|
@ -315,30 +315,37 @@ migrate_ops_repo() {
|
||||||
echo "── Ops repo migration ───────────────────────────────────"
|
echo "── Ops repo migration ───────────────────────────────────"
|
||||||
echo "Checking ${ops_root} for missing directories and files..."
|
echo "Checking ${ops_root} for missing directories and files..."
|
||||||
|
|
||||||
|
# Change to ops_root directory to ensure all git operations use the correct repo
|
||||||
|
# This prevents "fatal: not in a git directory" errors from stray git commands
|
||||||
|
local orig_dir
|
||||||
|
orig_dir=$(pwd)
|
||||||
|
cd "$ops_root" || {
|
||||||
|
echo "Error: failed to change to ${ops_root}" >&2
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
local migrated=false
|
local migrated=false
|
||||||
|
|
||||||
# Canonical ops repo structure (post #407)
|
# Canonical ops repo structure (post #407)
|
||||||
# Directories to ensure exist with .gitkeep files
|
# Directories to ensure exist with .gitkeep files
|
||||||
local -a dir_keepfiles=(
|
local -a dir_keepfiles=(
|
||||||
"${ops_root}/vault/pending/.gitkeep"
|
"vault/pending/.gitkeep"
|
||||||
"${ops_root}/vault/approved/.gitkeep"
|
"vault/approved/.gitkeep"
|
||||||
"${ops_root}/vault/fired/.gitkeep"
|
"vault/fired/.gitkeep"
|
||||||
"${ops_root}/vault/rejected/.gitkeep"
|
"vault/rejected/.gitkeep"
|
||||||
"${ops_root}/knowledge/.gitkeep"
|
"knowledge/.gitkeep"
|
||||||
"${ops_root}/evidence/engagement/.gitkeep"
|
"evidence/engagement/.gitkeep"
|
||||||
"${ops_root}/evidence/red-team/.gitkeep"
|
"evidence/red-team/.gitkeep"
|
||||||
"${ops_root}/evidence/holdout/.gitkeep"
|
"evidence/holdout/.gitkeep"
|
||||||
"${ops_root}/evidence/evolution/.gitkeep"
|
"evidence/evolution/.gitkeep"
|
||||||
"${ops_root}/evidence/user-test/.gitkeep"
|
"evidence/user-test/.gitkeep"
|
||||||
"${ops_root}/sprints/.gitkeep"
|
"sprints/.gitkeep"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create missing directories and .gitkeep files
|
# Create missing directories and .gitkeep files
|
||||||
for keepfile in "${dir_keepfiles[@]}"; do
|
for keepfile in "${dir_keepfiles[@]}"; do
|
||||||
local dir
|
|
||||||
dir=$(dirname "$keepfile")
|
|
||||||
if [ ! -f "$keepfile" ]; then
|
if [ ! -f "$keepfile" ]; then
|
||||||
mkdir -p "$dir"
|
mkdir -p "$(dirname "$keepfile")"
|
||||||
touch "$keepfile"
|
touch "$keepfile"
|
||||||
echo " + Created: ${keepfile}"
|
echo " + Created: ${keepfile}"
|
||||||
migrated=true
|
migrated=true
|
||||||
|
|
@ -347,9 +354,9 @@ migrate_ops_repo() {
|
||||||
|
|
||||||
# Template files to create if missing (starter content)
|
# Template files to create if missing (starter content)
|
||||||
local -a template_files=(
|
local -a template_files=(
|
||||||
"${ops_root}/portfolio.md"
|
"portfolio.md"
|
||||||
"${ops_root}/prerequisites.md"
|
"prerequisites.md"
|
||||||
"${ops_root}/RESOURCES.md"
|
"RESOURCES.md"
|
||||||
)
|
)
|
||||||
|
|
||||||
for tfile in "${template_files[@]}"; do
|
for tfile in "${template_files[@]}"; do
|
||||||
|
|
@ -371,26 +378,33 @@ migrate_ops_repo() {
|
||||||
# Commit and push changes if any were made
|
# Commit and push changes if any were made
|
||||||
if [ "$migrated" = true ]; then
|
if [ "$migrated" = true ]; then
|
||||||
# Auto-configure repo-local git identity if missing
|
# Auto-configure repo-local git identity if missing
|
||||||
if [ -z "$(git -C "$ops_root" config user.name 2>/dev/null)" ]; then
|
if [ -z "$(git config user.name 2>/dev/null)" ]; then
|
||||||
git -C "$ops_root" config user.name "disinto-admin"
|
git config user.name "disinto-admin"
|
||||||
fi
|
fi
|
||||||
if [ -z "$(git -C "$ops_root" config user.email 2>/dev/null)" ]; then
|
if [ -z "$(git config user.email 2>/dev/null)" ]; then
|
||||||
git -C "$ops_root" config user.email "disinto-admin@localhost"
|
git config user.email "disinto-admin@localhost"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git -C "$ops_root" add -A
|
git add -A
|
||||||
if ! git -C "$ops_root" diff --cached --quiet 2>/dev/null; then
|
if ! git diff --cached --quiet 2>/dev/null; then
|
||||||
git -C "$ops_root" commit -m "chore: migrate ops repo structure to canonical layout" -q
|
if ! git commit -m "chore: migrate ops repo structure to canonical layout" -q; then
|
||||||
|
echo "Error: failed to commit migration changes" >&2
|
||||||
|
cd "$orig_dir"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
# Push if remote exists
|
# Push if remote exists
|
||||||
if git -C "$ops_root" remote get-url origin >/dev/null 2>&1; then
|
if git remote get-url origin >/dev/null 2>&1; then
|
||||||
if git -C "$ops_root" push origin "${primary_branch}" -q 2>/dev/null; then
|
if ! git push origin "${primary_branch}" -q 2>/dev/null; then
|
||||||
echo "Migrated: ops repo structure updated and pushed"
|
|
||||||
else
|
|
||||||
echo "Warning: failed to push migration to ops repo" >&2
|
echo "Warning: failed to push migration to ops repo" >&2
|
||||||
|
else
|
||||||
|
echo "Migrated: ops repo structure updated and pushed"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
echo " (all directories and files already present)"
|
echo " (all directories and files already present)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Return to original directory
|
||||||
|
cd "$orig_dir"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue