Skip to content

fix(pull): keep files-only local commits on first pull - #352

Merged
runkids merged 6 commits into
mainfrom
fix/first-pull-keep-local-files
Oct 3, 2026
Merged

runkids merged 6 commits into
mainfrom
fix/first-pull-keep-local-files

Conversation

@runkids

@runkids runkids commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Type

  • Bug fix
  • Small improvement (docs, typo, minor refactor)
  • Feature proposal (proposals/ only — see CONTRIBUTING.md)

Summary

On a first pull (no upstream yet), FirstPull decided 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 and reset --hard onto 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 .gitignore counts too (via ls-files --cached --others --exclude-standard, so ignored files like .DS_Store don'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 local config.yaml — on the merge path as well as with --force, since git treats ignored files as expendable. Tracked as a follow-up.

  • Side effect in 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: pull merges both sides, pull --force replaces local.
  • pull.md updated 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)

  • New regression test TestFirstPull_KeepsFilesOnlyLocalCommits failed before the fix (local committed file was discarded) and passes after.
  • internal/git, internal/server, cmd/skillshare targeted tests pass; integration TestPull* / TestInit* pass after make build.
  • make fmt-check lint docs-check and python3 scripts/ai-context.py check pass.
  • Full make check was not green locally: run from a git worktree, many git-dependent tests fail with not a git repository because the worktree's .git points to a host path the container can't see (the same packages pass on the main checkout). Integration also has 5 failures on clean main (TestCompletion_*_AllShells, TestExtrasMemory_*) unrelated to this change. CI is the authoritative full run.

Checklist

  • I've read CONTRIBUTING.md
  • Tests included and passing (make check) — for code changes (targeted; see Verification for full-run caveats)
  • No unrelated changes in the diff
  • Scope is focused — one concern per PR

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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-03T09:33:34.320292Z dd5eb78 Manual request
ℹ️ 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" or "@codex security review".

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread internal/git/info.go Outdated
}
for _, e := range entries {
if e.IsDir() && e.Name() != ".git" {
if e.Name() != ".git" && e.Name() != ".gitignore" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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".

Comment thread cmd/skillshare/init.go
}

hasLocalSkills, err := gitops.HasLocalSkillDirs(sourcePath)
hasLocalSkills, err := gitops.HasLocalContent(sourcePath)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.
@runkids

runkids commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread internal/git/info.go
for _, e := range entries {
if e.IsDir() && e.Name() != ".git" {
for _, path := range strings.Split(string(out), "\x00") {
if path != "" && path != ".gitignore" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.
@runkids

runkids commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread internal/git/info.go Outdated
after, _ := os.ReadFile(filepath.Join(dir, ".gitignore"))
var dropped []string
for _, line := range strings.Split(string(before), "\n") {
line = strings.TrimSpace(line)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.
@runkids

runkids commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread internal/git/info.go
return false, fmt.Errorf("list local files: %w", err)
}
for _, path := range strings.Split(string(out), "\x00") {
if path != "" && path != ".gitignore" {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

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.
@runkids

runkids commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: dd5eb78d14

ℹ️ 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".

@runkids
runkids merged commit 6f3d6a3 into main Oct 3, 2026
8 checks passed
@runkids
runkids deleted the fix/first-pull-keep-local-files branch October 3, 2026 09:38
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.

1 participant