Skip to content

Conversation

@Ray0907
Copy link

@Ray0907 Ray0907 commented Oct 4, 2025

Fixes #733

When users delete a branch and create a new one, the spec directory
name no longer matches the branch name, causing spec-kit to fail.

This fix adds automatic detection of mismatched spec directories and
provides clear instructions to fix the issue using git mv.

Changes:

  • Add check_and_fix_spec_directory_mismatch() function to common.sh
  • Integrate mismatch check into setup-plan.sh and check-prerequisites.sh
  • Handle three scenarios: single orphaned dir, multiple orphaned dirs, no dir
  • Provide actionable git mv commands in warning messages

  Fixes github#733

  When users delete a branch and create a new one, the spec directory
  name no longer matches the branch name, causing spec-kit to fail.

  This fix adds automatic detection of mismatched spec directories and
  provides clear instructions to fix the issue using git mv.

  Changes:
  - Add check_and_fix_spec_directory_mismatch() function to common.sh
  - Integrate mismatch check into setup-plan.sh and check-prerequisites.sh
  - Handle three scenarios: single orphaned dir, multiple orphaned dirs, no
  dir
  - Provide actionable git mv commands in warning messages
@Ray0907 Ray0907 requested a review from localden as a code owner October 4, 2025 06:31
Copilot AI review requested due to automatic review settings October 4, 2025 06:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds automatic detection and warning for spec directory mismatches when branch names don't align with spec directory names, typically occurring after branch deletion and recreation. This prevents spec-kit failures by providing clear remediation instructions.

  • Implements check_and_fix_spec_directory_mismatch() function to detect orphaned spec directories
  • Integrates mismatch detection into both setup and prerequisite checking workflows
  • Provides actionable git mv commands to resolve directory naming conflicts

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
scripts/bash/common.sh Adds core logic to detect spec directory mismatches and generate appropriate warning messages
scripts/bash/setup-plan.sh Integrates mismatch check into the setup workflow
scripts/bash/check-prerequisites.sh Adds mismatch check to prerequisite validation with paths-only mode support

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

  robustness
  - Add variable validation and nullglob protection
  - Skip symlinks and hidden directories
  - Optimize git branch lookups
  - Add comprehensive function documentation
Copilot AI review requested due to automatic review settings November 2, 2025 04:15
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Ray0907 and others added 2 commits November 2, 2025 12:22
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings November 2, 2025 04:22
Ray0907 and others added 2 commits November 2, 2025 12:23
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings November 2, 2025 04:40
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

# Check if branch and spec directory are in sync
check_and_fix_spec_directory_mismatch
result=$?
if [[ $result -ne 0 && $result -ne 1 ]]; then
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return code handling logic is unclear. According to the function documentation (lines 167-172 in common.sh), the function only returns 0 (success/no mismatch) or 1 (mismatch detected). The condition if [[ $result -ne 0 && $result -ne 1 ]] suggests there are other return codes, but none are documented or implemented. Either simplify this to handle only the documented return codes, or update the function documentation to specify what other return codes mean.

Suggested change
if [[ $result -ne 0 && $result -ne 1 ]]; then
if [[ $result -eq 1 ]]; then

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +41
check_and_fix_spec_directory_mismatch
result=$?
if [[ $result -ne 0 && $result -ne 1 ]]; then
exit 1
fi
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent error handling between setup-plan.sh and check-prerequisites.sh. In check-prerequisites.sh (line 87), the function is called with || exit 1, treating any non-zero return as an error. Here, return code 1 is explicitly allowed to continue. This inconsistency suggests different intentions that should be clarified with comments or unified.

Copilot uses AI. Check for mistakes.

if [[ -d "$specs_dir" ]] && has_git; then
# Get all existing branch names for efficient lookup (Bash 3.2 compatible)
local existing_branches=$(git for-each-ref refs/heads/ --format='%(refname:short)' 2>/dev/null | tr '\n' '|')
Copy link

Copilot AI Nov 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing_branches variable will have a trailing pipe character when branches exist, but will be empty when no branches exist. Line 226's check echo \"|${existing_branches}\" | grep -qF \"|${dirname}|\" will fail for the first branch name when existing_branches is non-empty because of the missing leading pipe in existing_branches. The variable should be |branch1|branch2| format, but tr '\\n' '|' produces branch1|branch2|. This will cause false positives for orphan detection.

Suggested change
local existing_branches=$(git for-each-ref refs/heads/ --format='%(refname:short)' 2>/dev/null | tr '\n' '|')
local existing_branches="|$(git for-each-ref refs/heads/ --format='%(refname:short)' 2>/dev/null | tr '\n' '|')"

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check branch name while developing

1 participant