fix: use git reset for clean history on init --remote, skip project auto-detect for global flags

- tryPullAfterRemoteSetup: replace git pull/merge with git reset --hard
  to avoid merge commits and ff-only/conflict issues when pulling from
  remote into a freshly initialized repo
- Add hasGlobalOnlyInitFlags() so init --remote works correctly even
  when cwd has .skillshare/config.yaml (project mode auto-detection)
- Update cross-machine-sync doc to reflect reset behavior
This commit is contained in:
Willie
2026-02-13 14:21:36 +08:00
parent f4be50bdd7
commit 11e18dce00
3 changed files with 47 additions and 16 deletions
+19
View File
@@ -1,5 +1,24 @@
# Changelog
## [0.11.6] - 2026-02-11
### Added
- **Auto-pull on `init --remote`** — when remote has existing skills, init automatically fetches and syncs them; no manual `git clone` or `git pull` needed
- **Auto-commit on `git init`** — `init` creates an initial commit (with `.gitignore`) so `push`/`pull`/`stash` work immediately
- **Git identity fallback** — if `user.name`/`user.email` aren't configured, sets repo-local defaults (`skillshare@local`) with a hint to set your own
- **Git remote error hints** — `push`, `pull`, and `init --remote` now show actionable hints for SSH, URL, and network errors
- **Docker sandbox `--bare` mode** — `make sandbox-bare` starts the playground without auto-init for manual testing
- **Docker sandbox `--volumes` reset** — `make sandbox-reset` removes the playground home volume for a full reset
### Changed
- **`init --remote` auto-detection** — global-only flags (`--remote`, `--source`, etc.) now skip project-mode auto-detection, so `init --remote` works from any directory
- **Target multi-select labels** — shortened to `name (status)` for readability; paths shown during detection phase instead
### Fixed
- `init --remote` on second machine no longer fails with "Local changes detected" or merge conflicts
- `init --remote` produces clean linear git history (no merge commits from unrelated histories)
- Pro tip message only shown when built-in skill is actually installed
## [0.11.5] - 2026-02-11
### Added
+27 -15
View File
@@ -292,6 +292,19 @@ func printInitSuccess(sourcePath string, dryRun bool, skillInstalled bool) {
}
}
// hasGlobalOnlyInitFlags returns true if args contain flags only valid for global init
// (e.g. --remote, --source). Used to skip project-mode auto-detection.
func hasGlobalOnlyInitFlags(args []string) bool {
for _, arg := range args {
switch arg {
case "--remote", "--source", "-s", "--copy-from", "-c", "--no-copy",
"--git", "--no-git", "--skill", "--no-skill":
return true
}
}
return false
}
func cmdInit(args []string) error {
mode, rest, err := parseModeArgs(args)
if err != nil {
@@ -309,7 +322,7 @@ func cmdInit(args []string) error {
return fmt.Errorf("cannot determine home directory: %w", err)
}
if mode == modeAuto {
if mode == modeAuto && !hasGlobalOnlyInitFlags(rest) {
if cwd, cwdErr := os.Getwd(); cwdErr == nil && projectConfigExists(cwd) {
applyModeLabel(modeProject)
return cmdInitProject(rest)
@@ -881,14 +894,24 @@ func tryPullAfterRemoteSetup(sourcePath string) bool {
if hasLocalSkills {
spinner.Warn("Remote has existing skills, but local skills also exist")
ui.Info(" Push local: skillshare push")
ui.Info(" Pull remote: cd %s && git pull origin %s --allow-unrelated-histories", sourcePath, remoteBranch)
ui.Info(" Pull remote: cd %s && git fetch origin && git -c merge.ff=false merge origin/%s --allow-unrelated-histories", sourcePath, remoteBranch)
return true
}
// Local is empty — auto-pull from remote
// Local is empty — reset to remote branch for clean linear history.
// This is safe because we verified hasLocalSkills is false above.
spinner.Update("Pulling skills from remote...")
// Get local branch name
resetCmd := exec.Command("git", "reset", "--hard", "origin/"+remoteBranch)
resetCmd.Dir = sourcePath
if output, err := resetCmd.CombinedOutput(); err != nil {
spinner.Fail("Failed to pull from remote")
fmt.Println(string(output))
ui.Info(" Try manually: cd %s && git reset --hard origin/%s", sourcePath, remoteBranch)
return true
}
// Set up tracking so push/pull work without specifying remote
localBranch := "main"
branchCmd := exec.Command("git", "branch", "--show-current")
branchCmd.Dir = sourcePath
@@ -897,17 +920,6 @@ func tryPullAfterRemoteSetup(sourcePath string) bool {
localBranch = b
}
}
pullCmd := exec.Command("git", "pull", "origin", remoteBranch, "--allow-unrelated-histories")
pullCmd.Dir = sourcePath
if output, err := pullCmd.CombinedOutput(); err != nil {
spinner.Fail("Failed to pull from remote")
fmt.Println(string(output))
ui.Info(" Try manually: cd %s && git pull origin %s --allow-unrelated-histories", sourcePath, remoteBranch)
return true
}
// Set up tracking branch
trackCmd := exec.Command("git", "branch", "--set-upstream-to=origin/"+remoteBranch, localBranch)
trackCmd.Dir = sourcePath
trackCmd.Run() // best-effort
+1 -1
View File
@@ -74,7 +74,7 @@ Init automatically detects that the remote has existing skills and pulls them do
:::info What happens behind the scenes
1. Creates source directory and initializes git
2. Adds remote and runs `git fetch`
3. Detects remote has skills → auto-pulls them
3. Detects remote has skills → resets local to match remote
4. Sets up tracking branch
5. Auto-detects and configures local targets
:::