-
Notifications
You must be signed in to change notification settings - Fork 965
feat: add .gitkeep files to preserve empty directories (#269) #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yha9806
wants to merge
5
commits into
Fission-AI:main
Choose a base branch
from
yha9806:fix/issue-269-empty-folders
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
a359909
feat: add .gitkeep files to preserve empty directories (#269)
yha9806 90596db
chore: archive add-gitkeep-empty-folders change
yha9806 2f715d1
fix: change prepare to postinstall for npm install from git
yha9806 a046536
feat: commit dist directory for npm install from git
yha9806 ca78a3b
Merge main: resolve package.json conflict
yha9806 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| # Add .gitkeep Files to Empty Folders | ||
|
|
||
| ## Why | ||
|
|
||
| Git does not track empty directories. When `openspec init` creates the directory structure with empty `specs/`, `changes/`, and `changes/archive/` folders, these directories disappear after a commit if no files exist in them. | ||
|
|
||
| This causes workflow issues: | ||
| - After cloning a fresh repository, running `openspec list` fails because the expected directories don't exist | ||
| - New team members encounter errors when trying to use OpenSpec commands | ||
| - Users must manually recreate directories or remember to add placeholder files | ||
|
|
||
| ## What Changes | ||
|
|
||
| Modify the `openspec init` command to create `.gitkeep` files in the three empty directories that need to persist in Git: | ||
| - `openspec/specs/` | ||
| - `openspec/changes/` | ||
| - `openspec/changes/archive/` | ||
|
|
||
| The `.gitkeep` file is a widely-used convention to force Git to track empty directories. It's an empty file (or a file with a simple comment) that ensures the directory structure is preserved across clones. | ||
|
|
||
| ## Impact | ||
|
|
||
| **Users Affected**: All users who run `openspec init` | ||
|
|
||
| **Breaking Changes**: None | ||
|
|
||
| **Migration Required**: No - existing projects work as-is, but will benefit from running `openspec init` again in extend mode to add .gitkeep files | ||
|
|
||
| **Dependencies**: None | ||
|
|
||
| **Timeline**: Quick fix - can be completed in one implementation session |
34 changes: 34 additions & 0 deletions
34
openspec/changes/add-gitkeep-empty-folders/specs/cli-init/spec.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| # CLI Init Specification Changes | ||
|
|
||
| ## MODIFIED Requirements | ||
|
|
||
| ### Requirement: Directory Creation | ||
| The command SHALL create the complete OpenSpec directory structure with all required directories and files, including `.gitkeep` files to ensure empty directories are tracked by Git. | ||
|
|
||
| #### Scenario: Creating OpenSpec structure | ||
| - **WHEN** `openspec init` is executed | ||
| - **THEN** create the following directory structure: | ||
| ``` | ||
| openspec/ | ||
| ├── project.md | ||
| ├── AGENTS.md | ||
| ├── specs/ | ||
| │ └── .gitkeep | ||
| └── changes/ | ||
| ├── .gitkeep | ||
| └── archive/ | ||
| └── .gitkeep | ||
| ``` | ||
| - **AND** each `.gitkeep` file SHALL be an empty file that forces Git to track the directory | ||
|
|
||
| #### Scenario: Preserving empty directories in Git | ||
| - **WHEN** a user commits and pushes the OpenSpec structure to a Git repository | ||
| - **THEN** the `specs/`, `changes/`, and `changes/archive/` directories SHALL persist in the repository | ||
| - **AND** after cloning the repository, all three directories SHALL exist | ||
| - **AND** `openspec list` SHALL work immediately without manual directory creation | ||
|
|
||
| #### Scenario: Working with fresh clones | ||
| - **GIVEN** a repository initialized with OpenSpec | ||
| - **WHEN** a new team member clones the repository | ||
| - **THEN** running `openspec list` SHALL succeed without errors | ||
| - **AND** no manual directory creation SHALL be required |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| # Tasks | ||
|
|
||
| ## Implementation | ||
| - [ ] Modify `src/core/init.ts` `createDirectoryStructure` method to create `.gitkeep` files in empty directories | ||
| - [ ] Add `.gitkeep` file creation for `openspec/specs/` | ||
| - [ ] Add `.gitkeep` file creation for `openspec/changes/` | ||
| - [ ] Add `.gitkeep` file creation for `openspec/changes/archive/` | ||
|
|
||
| ## Testing | ||
| - [ ] Add test case verifying `.gitkeep` exists in `specs/` after init | ||
| - [ ] Add test case verifying `.gitkeep` exists in `changes/` after init | ||
| - [ ] Add test case verifying `.gitkeep` exists in `changes/archive/` after init | ||
| - [ ] Run existing test suite to ensure no regressions | ||
|
|
||
| ## Validation | ||
| - [ ] Run `openspec validate add-gitkeep-empty-folders --strict` and resolve all issues | ||
| - [ ] Test `openspec init` manually in a fresh directory | ||
| - [ ] Verify Git tracks the empty directories with `.gitkeep` files | ||
| - [ ] Test `openspec list` works immediately after clone in a new repository |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if there's a different way to solve this. This makes sense but I'm a reluctant to add in .gitkeep files that users will most likely forget to delete.
Maybe we can look into making init self-healing or finding another way to always ensure we re-create these folders if these are ever missing.