Skip to content

fix(pull): keep the local config.yaml when a later pull brings a tracked copy - #362

Merged
runkids merged 15 commits into
mainfrom
fix/keep-local-config
Oct 3, 2026
Merged

runkids merged 15 commits into
mainfrom
fix/keep-local-config

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

Follow-up to #357 for #353.

#357 refuses a root-scope first pull when the remote tracks config.yaml. Once upstream is set, though, a later pull that merges in a remote-tracked config.yaml (for example, another machine force-added it) still replaced this machine's copy. Git treats the ignored file as expendable during the merge.

This PR keeps the local config.yaml on those later pulls and warns:

! The remote tracks config.yaml; kept this machine's copy
  Remove it from the remote: skillshare push

push already untracks config.yaml at root scope (EnsureConfigUntracked), so the suggested command fixes the remote.

Pull Remote tracks config.yaml
First pull (no upstream) Refused — unchanged from #357
Later pull: CLI pull, dashboard Pull / Sync both ways Local copy kept, warning shown
push --pull Local copy kept, and the push removes config.yaml from the remote

Changes

  • internal/git/scope.go: KeepLocalConfig(dir) snapshots config.yaml (a regular file or a symlink, as dotfiles setups use) and returns a restore that writes it back and reports whether the repo tracks config.yaml after the pull (so an identical tracked copy still warns).
  • cmd/skillshare/pull.go: integrateRemote wraps the later-pull path at root scope, so both pull and push --pull are covered.
  • cmd/skillshare/push.go: after the pull, push --pull re-runs EnsureConfigUntracked and commits the removal, so the same push removes config.yaml from the remote.
  • internal/server/handler_git.go: same for the dashboard pull (upstream branch only); the warning goes into warnings.
  • push.md (EN + 4 locales): one sentence on push --pull at root scope.
  • pull.md (EN + ja / ko / zh-Hans / zh-Hant): the root-scope paragraph from fix(pull): refuse root-scope first pull when remote tracks config.yaml #357 now describes both cases.

Linked Issue

Refs #353 (fixed for first pulls by #357; this covers later pulls).

Verification (devcontainer image)

  • internal/git: KeepLocalConfig tests for a later pull that brings a tracked copy, a symlinked config, and no false warning when the remote leaves config.yaml alone.
  • internal/git: identical-content tracked copy still reports tracking.
  • internal/server: TestHandlePull_RootScopeKeepsLocalConfig.
  • Integration: TestGitRoot_PushPullUntracksConfigBroughtInByPull (failed before the fix: remote kept config.yaml).
  • Integration: TestGitRoot_PullKeepsLocalConfigWhenRemoteTracksIt. It failed before the fix: the later pull replaced the local config. It passes after, and it also checks that the suggested skillshare push removes config.yaml from the remote and keeps it on disk.
  • fix(pull): refuse root-scope first pull when remote tracks config.yaml #357's refusal tests still pass.
  • make build, make fmt-check lint docs-check, go test ./... (full, including integration) pass.
  • website pnpm run build succeeds for all five locales.

Checklist

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

…ked copy

#357 refuses a root-scope first pull when the remote tracks config.yaml, but once upstream is set, a pull that merges in a remote-tracked copy still replaced this machine's config: Git treats the ignored file as expendable. Snapshot config.yaml around later pulls (CLI pull, push --pull, and the dashboard), restore it, and warn so the user can untrack it with push.

Refs #353
@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-03T17:45:35.070791Z e90eccc 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.

@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: 24bd99941e

ℹ️ 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 cmd/skillshare/push.go Resolved
Comment thread internal/git/scope.go Resolved
… copies

push --pull ran the root safety sweep before integrating the remote, so a
pull that brought in a remote-tracked config.yaml was pushed back as-is:
the remote kept tracking it and the next first pull elsewhere was refused.
Re-run EnsureConfigUntracked after the pull and commit the removal before
pushing.

The warning also depended on the pull changing the local bytes, so a
tracked copy identical to this machine's went unreported. KeepLocalConfig's
restore now reports whether the repo tracks config.yaml after the pull.
@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: eecbc76928

ℹ️ 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/scope.go Resolved
KeepLocalConfig wrote its snapshot back after every root-scope pull, so an
edit made to an untracked config.yaml while the pull ran was silently
replaced by the stale copy. Git only rewrites config.yaml when it is
tracked before or after the pull, so restore only in that case.
@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: 9f144fe454

ℹ️ 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/scope.go Resolved
Gating the restore on "tracked before or after" still overwrote edits made
during a pull when config.yaml was already tracked and the pull left it
alone. Compare config.yaml's index entry (mode, blob, stage) before and
after the pull instead; a merge, reset or conflict that touches the file
changes it, and anything else keeps the current file.
@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: 7b67dbd3fe

ℹ️ 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/scope.go Resolved
…cks it

The warning followed the local index, so a config.yaml tracked only by a
local, unpushed commit was reported as tracked by the remote, and the
suggested push would publish it in history. Check the upstream tree with
RemoteTracksConfig("@{u}") instead.
@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: 71f42096a2

ℹ️ 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/scope.go Resolved
A merge that brought in a tracked config.yaml and conflicted elsewhere was
aborted, which deleted the file again and returned the index entry to its
pre-pull state, so restore saw no change and the local config was lost.
Also restore when the snapshotted file is missing after the pull.
@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: d0720a0e23

ℹ️ 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 cmd/skillshare/push.go Resolved
EnsureConfigUntracked only checked that a "config.yaml" line existed, so a
pulled .gitignore with a later "!config.yaml" left the file unignored and
the following `git add -A` tracked this machine's copy again. Check the
effective ignore state and append an overriding entry when needed.
@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: aae1af517b

ℹ️ 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 cmd/skillshare/push.go Resolved
Comment thread internal/git/scope.go Resolved
push --pull committed only when EnsureConfigUntracked removed an index
entry, so a pulled .gitignore that stopped ignoring config.yaml was
repaired locally but never pushed, leaving the tree dirty. Commit whenever
the safety step leaves changes.

KeepLocalConfig skipped the restore when the bytes matched, so a checkout
that rewrote config.yaml with the default mode dropped this machine's
restrictive permissions. Compare the mode too, and chmod after writing
since WriteFile's mode is masked by umask.
@runkids

runkids commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@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: c386029ac1

ℹ️ 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/scope.go Resolved
A pull that checks out a tracked config.yaml/ tree replaces the ignored
local file with a directory, which os.Remove cannot delete, so restore
failed and the local config stayed lost. Remove a directory there before
writing the snapshot back; its contents are in Git. EnsureConfigUntracked
now untracks recursively so push can remove that tree too.
@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: db866989b8

ℹ️ 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/scope.go
if configIndexEntry(dir) == entryBefore && !errors.Is(statErr, fs.ErrNotExist) {
return remoteTracks, nil
}
_, err := put()

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 Preserve edits made after Git updates config

When the upstream changes config.yaml and another process writes a newer machine-local configuration after Git checks out that change but before this callback runs, the changed index entry forces put() to remove that newer file and restore the stale pre-pull snapshot. Fresh evidence beyond the prior concurrency fixes is that those fixes only skip restoration when the index entry is unchanged; compare the current file with the checked-out index version before overwriting it so post-checkout edits are preserved.

AGENTS.md reference: AGENTS.md:L13-L14

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 a21b913. When the pull changed config.yaml's index entry, restore now checks whether the file on disk still matches the blob the pull checked out, using git hash-object against the stage-0 entry. If it doesn't, someone wrote a newer copy after the checkout, so restore keeps that copy. Conflicts, removals, directories and symlink entries still restore the snapshot. Added TestKeepLocalConfig_KeepsEditMadeAfterCheckout; it failed before and passes now.

Comment thread internal/git/scope.go Resolved
Restore wrote the snapshot back whenever the pull changed config.yaml's
index entry, even when a newer copy had been written after Git checked it
out. Skip the restore when the file on disk no longer matches the blob the
pull checked out.

A dry-run push or commit only previewed untracking config.yaml, so when a
later "!config.yaml" rule un-ignored it the preview listed config.yaml to
commit while a real run repairs .gitignore instead. Preview that repair.
@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: a21b913ff4

ℹ️ 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 cmd/skillshare/push.go Outdated
return err
} else if repaired != "" {
spinner = ui.StartSpinner("Committing...")
if err := stageAndCommit(source, "Keep config.yaml out of version control", spinner); err != nil {

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 Restrict the post-pull safety commit to safety files

When another process edits any non-config file while the network pull is running, getGitChanges observes that edit here and stageAndCommit stages every path with git add -A; the edit is then committed under the config-safety message and pushed without the user explicitly including it. The initial commit cannot cover changes made after it, so commit only the staged config.yaml removal and .gitignore repair, or abort if unexpected paths are dirty.

AGENTS.md reference: AGENTS.md:L14-L14

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 e90eccc. The post-pull step in push --pull now calls commitConfigSafety, which stages only .gitignore on top of the git rm --cached that EnsureConfigUntracked already staged. It then commits the index as staged; a pathspec commit would re-add config.yaml from disk. Other edits made while the pull ran stay uncommitted and are not pushed. Added TestCommitConfigSafety_LeavesOtherEditsUncommitted.

Comment thread internal/git/scope.go Outdated
Comment on lines +286 to +287
if info, err := os.Lstat(filepath.Join(dir, "config.yaml")); err != nil || !info.Mode().IsRegular() {
return false

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 Preserve post-checkout symlink updates

When the pull changes the tracked config and a dotfiles manager or another process replaces config.yaml with a newer symlink before restoration, this non-regular-file branch reports no concurrent edit, so put() removes that symlink and recreates the stale pre-pull snapshot. Fresh evidence beyond the prior concurrency fix is that symlinks are explicitly excluded from the hash comparison even though this change supports symlinked configs; compare the current link target with the checked-out index value before overwriting it.

AGENTS.md reference: AGENTS.md:L14-L14

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 e90eccc. editedAfterCheckout now handles links. A symlink where the pull checked out a regular entry counts as a newer local edit, since Git writes a file there and not a link. For a tracked symlink entry (120000), the current link target is hashed and compared with the checked-out blob. Added TestKeepLocalConfig_KeepsSymlinkMadeAfterCheckout; it failed before (the snapshot replaced the link) and passes now.

The post-pull safety step in push --pull ran `git add -A`, so an edit made
by another process while the pull ran was committed and pushed under the
config-safety message. Stage only .gitignore on top of the config.yaml
removal and commit the index as staged.

The post-checkout edit check skipped symlinks, so a dotfiles manager that
replaced config.yaml with a newer link after the checkout had it replaced
by the stale snapshot. Treat a link where Git checked out a file, or a
different link target, as a newer local edit.
@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: e90eccc362

ℹ️ 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 cmd/skillshare/gitroot.go Outdated
}
if dryRun {
res.configUntracked = gitops.IsConfigTracked(dir)
res.ignoreRepair = !gitops.IsConfigIgnored(dir)

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 Preview explicit ignore-rule repairs under broader patterns

When config.yaml is already ignored by a broader rule such as *.yaml (or by .git/info/exclude), this returns ignoreRepair=false, although a real run still calls EnsureConfigUntracked, which appends the explicit config.yaml entry and commits .gitignore. Consequently push --dry-run can report nothing to commit while the corresponding real push creates and publishes a commit; base the preview on whether the explicit entry is missing in addition to the effective ignore result.

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 82eaf0a. The dry-run preview now uses ConfigGitignoreNeedsRepair, which is true when the explicit config.yaml entry is missing as well as when the file is not effectively ignored. That covers the *.yaml and .git/info/exclude cases. Added TestConfigGitignoreNeedsRepair_ExplicitEntryUnderBroaderRule.

Comment thread cmd/skillshare/push.go
// commitConfigSafety commits the config.yaml removal and .gitignore repair
// EnsureConfigUntracked made, leaving any other worktree changes unstaged.
func commitConfigSafety(source string) error {
add := exec.Command("git", "add", "--", ".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 Avoid staging concurrent edits to the entire ignore file

When another process edits .gitignore while the network pull is running, this command stages the complete file, including that unrelated edit, and the following commit pushes it under the config-safety message. Fresh evidence beyond the prior path-scoping fix is that limiting git add to .gitignore still does not limit it to the safety hunk; verify the file still matches the pulled version or stage only the generated config.yaml rule and abort on concurrent changes.

AGENTS.md reference: AGENTS.md:L14-L14

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 82eaf0a. commitConfigSafety now checks that .gitignore differs from its staged version only by appended config.yaml lines. If anything else changed, it commits nothing and asks the user to commit .gitignore and run skillshare push. Added TestCommitConfigSafety_RefusesOtherGitignoreEdits.

… edits

A dry run previewed the .gitignore repair only when config.yaml was not
ignored at all, but a real run also appends the explicit entry when a
broader rule such as *.yaml ignores it. Preview whenever the entry is
missing too.

The post-pull safety commit staged the whole .gitignore, so an edit made
by another process while the pull ran was pushed with it. Refuse unless
the file only gained config.yaml lines over its staged version.
integrateRemote declared the KeepLocalConfig result with :=, shadowing the
named err that the deferred restore joins its failure into, so a failed
restore was swallowed and pull or push --pull went on to sync targets with
another machine's config.yaml. The dashboard pull replaced the pull's own
error with a bare 500 on a restore failure, losing the conflict response
and the ops log entry; join the errors so both are reported.
@runkids
runkids merged commit 475b176 into main Oct 3, 2026
8 checks passed
@runkids
runkids deleted the fix/keep-local-config branch October 3, 2026 17:58
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