Skip to content

Update init --codespaces to merge with existing devcontainer.json#7060

Merged
pelikhan merged 3 commits intomainfrom
copilot/update-devcontainer-file-creation
Dec 20, 2025
Merged

Update init --codespaces to merge with existing devcontainer.json#7060
pelikhan merged 3 commits intomainfrom
copilot/update-devcontainer-file-creation

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 20, 2025

The init --codespaces command previously created devcontainer.json in a subfolder (.devcontainer/gh-aw/) to avoid conflicts. This required users to manually merge configurations when a devcontainer already existed at the default location.

Changes

  • Modified ensureDevcontainerConfig() to check for existing devcontainer at .devcontainer/devcontainer.json first
  • Merge strategy when existing file found:
    • Preserves: name, image, existing extensions, features, postCreateCommand
    • Adds: GitHub Copilot extensions, gh-aw features, Codespaces repository permissions
    • Appends: gh-aw installation to postCreateCommand (if not present)
    • Updates: old copilot-cli versions to :latest
  • Creates at default location when no existing file found (not in subfolder)

Example

Existing devcontainer:

{
  "name": "Python Project",
  "image": "mcr.microsoft.com/devcontainers/python:3.11",
  "features": {
    "ghcr.io/devcontainers/features/docker-in-docker:2": {}
  }
}

After gh aw init --codespaces:

{
  "name": "Python Project",
  "image": "mcr.microsoft.com/devcontainers/python:3.11",
  "customizations": {
    "vscode": {
      "extensions": ["GitHub.copilot", "GitHub.copilot-chat"]
    },
    "codespaces": {
      "repositories": {
        "org/repo": { "permissions": { "workflows": "write", ... } }
      }
    }
  },
  "features": {
    "ghcr.io/devcontainers/features/docker-in-docker:2": {},
    "ghcr.io/devcontainers/features/github-cli:1": {},
    "ghcr.io/devcontainers/features/copilot-cli:latest": {}
  }
}

Helper Functions

  • buildRepositoryPermissions() - constructs permissions map for current/additional repos
  • mergeExtensions() - deduplicates extension arrays
  • mergeFeatures() - merges feature maps, updates copilot-cli versions
Original prompt

The "init --codespaces" command should update an existing devcontainer file if it already exists instead of creating a new file in a subfolder. If it does not exist, create devcontainer file in default location


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits December 20, 2025 14:59
- Modified ensureDevcontainerConfig to check for existing devcontainer at default location
- If .devcontainer/devcontainer.json exists, update it by merging gh-aw config
- If no devcontainer exists, create at default location instead of subfolder
- Update preserves existing name, image, extensions, features, and postCreateCommand
- Added helper functions for merging extensions and features
- Updated help text and success messages to reflect new behavior
- Updated all tests to validate new behavior including merge scenarios
- Manually tested both scenarios: new file creation and existing file update

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Comment thread pkg/cli/devcontainer.go
VSCode: &DevcontainerVSCode{
Extensions: []string{
"GitHub.copilot",
"GitHub.copilot-chat",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot add redhat yall extension

Copilot AI changed the title [WIP] Update init command to enhance devcontainer file handling Update init --codespaces to merge with existing devcontainer.json Dec 20, 2025
Copilot AI requested a review from pelikhan December 20, 2025 15:08
@pelikhan pelikhan marked this pull request as ready for review December 20, 2025 15:13
@pelikhan pelikhan merged commit e8607e2 into main Dec 20, 2025
39 of 40 checks passed
@pelikhan pelikhan deleted the copilot/update-devcontainer-file-creation branch December 20, 2025 15:13
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.

2 participants