Repository navigation
fix(pull): keep files-only local commits on first pull - #352
Conversation
FirstPull decided whether local history was worth keeping by looking only for root-level directories. Agents and extras repos hold their content as root-level files, so a repo with real local commits but no directories was treated as empty and reset --hard onto the remote, discarding that work without --force. Count any root entry except .git and the scaffold .gitignore as local content, matching how init already distinguishes a scaffold commit from real content. A scaffold-only repo still resets for a clean linear history.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Keep the ja, ko, zh-Hans and zh-Hant pull references in line with the English page now that any root file, not only a directory, counts as local content worth merging.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 306c06a56e
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
| for _, e := range entries { | ||
| if e.IsDir() && e.Name() != ".git" { | ||
| if e.Name() != ".git" && e.Name() != ".gitignore" { |
There was a problem hiding this comment.
Ignore Git-ignored files when detecting local content
When an otherwise scaffold-only repository contains an ignored root-level file such as .DS_Store or the root scope's ignored config.yaml, this filesystem scan reports local content even though the pull preflight's git status --porcelain considers the tree clean (git status -h exposes ignored entries only through --ignored). FirstPull consequently creates an unrelated-history merge instead of resetting to the remote, and can fail if the remote tracks the ignored path. Determine meaningful local content from tracked or non-ignored entries rather than every directory entry.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4498339. HasLocalContent now lists tracked and non-ignored files (ls-files --cached --others --exclude-standard) instead of scanning the directory, so ignored entries like .DS_Store or root-scope config.yaml no longer count as local content. TestHasLocalContent now covers an ignored .DS_Store staying "no content".
| } | ||
|
|
||
| hasLocalSkills, err := gitops.HasLocalSkillDirs(sourcePath) | ||
| hasLocalSkills, err := gitops.HasLocalContent(sourcePath) |
There was a problem hiding this comment.
Correct the pull guidance for files-only repositories
When init --remote finds a root-level local file and remote directory content, this new predicate routes into the warning that says skillshare pull "replaces local with remote." In this exact files-only case, however, pullFromRemote calls FirstPull(..., false), and the same predicate makes it merge and preserve the local files; replacement requires --force. The newly affected users therefore receive guidance opposite to the actual behavior, so describe the merge or explicitly recommend pull --force for replacement.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 4498339. The init warning now matches what FirstPull does with local content: skillshare pull merges and keeps both sides, skillshare pull --force replaces local with remote.
A raw directory scan counted ignored files such as .DS_Store as local content, so a scaffold-only repo merged unrelated history instead of resetting onto the remote and could fail when the remote tracks that path. Ask git for tracked and non-ignored files instead. init --remote also told users that 'skillshare pull' replaces local with remote, but with local content pull merges both sides; replacement needs --force. Show both options accurately.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4498339311
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for _, e := range entries { | ||
| if e.IsDir() && e.Name() != ".git" { | ||
| for _, path := range strings.Split(string(out), "\x00") { | ||
| if path != "" && path != ".gitignore" { |
There was a problem hiding this comment.
Restore root-scope ignore rules after resetting
When git_root: root contains only its generated .gitignore and the remote has directory content but lacks a config.yaml ignore rule, this exemption classifies the local repository as empty, so FirstPull or init performs reset --hard and removes the scope-aware ignore while the machine-local config.yaml remains. The fresh evidence beyond the earlier ignored-file report is the invariant in internal/git/scope.go:13-17 that root-scope repositories must never track this file; after the reset, git status reports config.yaml, causing the next pull to fail as dirty until a push repairs the ignore file. Preserve or reapply the required root-scope ignore rule after the reset.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 696a16c. Confirmed as a regression from 4498339: empty skills//agents/ dirs no longer count, so a scaffold-only root-scope repo now resets. The reset now goes through ResetKeepingIgnores, which carries any local .gitignore rule the reset drops (e.g. config.yaml) into .git/info/exclude — local-only, keeps the tree clean, no automatic commit. init --remote's reset path uses the same helper. TestFirstPull_ResetKeepsLocalIgnoreRules reproduced ?? config.yaml before the fix and passes now.
There was a problem hiding this comment.
Superseded by dd5eb78: ResetKeepingIgnores was removed. Directories count as local content again, so root scope never reaches the reset path it was patching.
With empty directories no longer counting as local content, a root-scope repo holding only its scaffold .gitignore now resets onto the remote. If the remote .gitignore lacks the config.yaml rule, the reset drops it and the machine-local config.yaml shows up as untracked, so the next pull fails as dirty. Carry any rule the reset drops into .git/info/exclude: it stays local, keeps the tree clean, and needs no automatic commit. init --remote's reset path uses the same helper.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 696a16c423
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| after, _ := os.ReadFile(filepath.Join(dir, ".gitignore")) | ||
| var dropped []string | ||
| for _, line := range strings.Split(string(before), "\n") { | ||
| line = strings.TrimSpace(line) |
There was a problem hiding this comment.
Keep significant whitespace in migrated ignore patterns
When a scaffold .gitignore contains a valid pattern whose leading whitespace is significant, such as foo, this trims it to foo before migrating it into info/exclude. After resetting against a remote that lacks the rule, Git will therefore ignore an ordinary foo file or skill directory, silently omitting it from later commits; Git's pattern syntax only discards unescaped trailing spaces, not leading whitespace (gitignore documentation). Preserve the raw pattern and use a separate normalized value only when checking for blank or comment lines.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in e267bc7. ResetKeepingIgnores now copies raw lines (only a trailing \r is dropped) and uses TrimSpace solely to detect blank lines; presence checks against the reset .gitignore and info/exclude compare raw lines exactly. TestResetKeepingIgnores_KeepsLeadingWhitespace reproduced a plain foo being ignored before the fix and passes now.
There was a problem hiding this comment.
Superseded by dd5eb78: ResetKeepingIgnores was removed. Directories count as local content again, so root scope never reaches the reset path it was patching.
Leading whitespace is part of a gitignore pattern, so trimming ' foo' to 'foo' before writing it to info/exclude made a plain foo file ignored and silently left out of later commits. Copy raw lines and only normalize to detect blanks.
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e267bc7830
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return false, fmt.Errorf("list local files: %w", err) | ||
| } | ||
| for _, path := range strings.Split(string(out), "\x00") { | ||
| if path != "" && path != ".gitignore" { |
There was a problem hiding this comment.
Protect config.yaml before classifying the root repo as empty
When a first-pull root-scope repository contains only the scaffold .gitignore, empty skills//agents/ directories, and its ignored machine-local config.yaml, this returns false. If a legacy or misconfigured remote tracks config.yaml, FirstPull therefore invokes ResetKeepingIgnores, whose git reset --hard overwrites the local config before any ignore rules are migrated; the loaded in-memory config lets this command finish, but the next invocation reads the remote copy. This is a regression from HasLocalSkillDirs, which treated those root-scope directories as local content and merged instead, and it violates the machine-local invariant documented in internal/git/scope.go:13-17. Git explicitly documents that --hard may overwrite obstructing untracked files, so preserve config.yaml before resetting or refuse this collision. Git reset documentation
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in dd5eb78 by removing the regression at its source instead of patching the reset path further: HasLocalContent counts directories again (plus tracked/non-ignored root files, the original fix), so a root-scope repo with skills//agents/ merges exactly as it did with HasLocalSkillDirs. ResetKeepingIgnores is gone. TestFirstPull_RootScopeScaffoldMergesAndStaysClean covers the scaffold + empty skills/ + ignored config.yaml case.
One correction on the premise: the old merge path does not protect config.yaml either. With a remote that tracks config.yaml, an unrelated-history merge silently overwrites the ignored local file too (git treats ignored files as expendable). Reproduced with plain git: merge succeeds and config.yaml ends up with the remote's content. That is pre-existing behavior on both the merge and --force paths, so I'm tracking it as a separate follow-up rather than widening this PR.
Dropping directories from the local-content check made a scaffold-only root-scope repo (empty skills/ and agents/) reset onto the remote, where it used to merge. Patching that new reset path kept surfacing edge cases (dropped ignore rules, whitespace-sensitive patterns, an ignored config.yaml overwritten by --hard). Count directories again, so root scope keeps its previous merge behavior, and drop ResetKeepingIgnores, which existed only to patch that path. The original fix stays: tracked or non-ignored root-level files now also count.
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Type
proposals/only — see CONTRIBUTING.md)Summary
On a first pull (no upstream yet),
FirstPulldecided whether local history was worth keeping by checking only for root-level directories (HasLocalSkillDirs). Agents and extras repos keep their content as root-level files, so a repo with real local commits but no directories was treated as empty andreset --hardonto the remote — discarding that work without--force.HasLocalSkillDirs→HasLocalContent: directories still count (so root scope keeps merging exactly as before), and now any tracked or non-ignored root file other than the scaffold.gitignorecounts too (vials-files --cached --others --exclude-standard, so ignored files like.DS_Storedon't). Only a repo with nothing but the scaffold resets for a clean linear history.Known pre-existing issue, not addressed here: if a remote tracks
config.yaml, a first pull at root scope overwrites the ignored localconfig.yaml— on the merge path as well as with--force, since git treats ignored files as expendable. Tracked as a follow-up.init --remote: when the remote has skills and the local source holds only files, init now asks the user to choose instead of resetting. Its guidance now matches actual behavior:pullmerges both sides,pull --forcereplaces local.pull.mdupdated to describe the actual rule, with matching ja / ko / zh-Hans / zh-Hant translations.Linked Issue
None — found during a review of the cross-device sync design.
Verification (devcontainer)
TestFirstPull_KeepsFilesOnlyLocalCommitsfailed before the fix (local committed file was discarded) and passes after.internal/git,internal/server,cmd/skillsharetargeted tests pass; integrationTestPull*/TestInit*pass aftermake build.make fmt-check lint docs-checkandpython3 scripts/ai-context.py checkpass.make checkwas not green locally: run from a git worktree, many git-dependent tests fail withnot a git repositorybecause the worktree's.gitpoints to a host path the container can't see (the same packages pass on the main checkout). Integration also has 5 failures on cleanmain(TestCompletion_*_AllShells,TestExtrasMemory_*) unrelated to this change. CI is the authoritative full run.Checklist
make check) — for code changes (targeted; see Verification for full-run caveats)