Skip to content

install: sparse clone inherits GIT_DIR and turns on sparse-checkout in the caller's repository #852

Closed

Description

@tomerzcod7

Summary

When skillshare install runs with GIT_DIR in its environment, the git commands of its sparse subdirectory clone act on the repository that GIT_DIR points at, not on the temporary clone. The result is that core.sparseCheckout is turned on in the caller's repository, and its info/sparse-checkout is set to the skill's subdirectory. The next checkout or merge in that repository then removes every tracked file outside that path.

Git exports GIT_DIR to hooks that run in a linked worktree (git worktree add), so a post-checkout or post-merge hook that runs skillshare install -p triggers this. In our case a merge removed about 28,000 files from the working tree before we noticed.

Reproduction (v0.30.5, git 2.50.1, macOS)

# A host repo that should never be touched
git init -q host && (cd host && echo a > a && mkdir x && echo b > x/b && git add -A && git commit -qm init)

# A project that installs one skill from a repo subdirectory
mkdir -p proj/.skillshare && cd proj && git init -q
cat > .skillshare/config.yaml <<'YAML'
targets:
  - name: universal
skills:
  - name: skillshare
    source: github.com/runkids/skillshare/skills/skillshare
YAML

GIT_DIR=../host/.git skillshare install -p --skip-audit

git -C ../host config --get core.sparseCheckout   # true
cat ../host/.git/info/sparse-checkout
# /*
# !/*/
# /skills/
# !/skills/*/
# /skills/skillshare/

Without GIT_DIR, the host repository is untouched.

Cause

gitCommand in internal/install/install_git.go passes the whole os.Environ() to git, so GIT_DIR, GIT_WORK_TREE, GIT_INDEX_FILE and the other repository-local variables reach git sparse-checkout set <subdir> in sparseCloneSubdir. The hooks package already strips these variables (sanitizedGitEnv in internal/hooks/gitcmd.go), but the install path doesn't.

Suggested fix

Apply the same filtering in internal/install's gitCommand, dropping the variables that git rev-parse --local-env-vars lists (or reusing sanitizedGitEnv). Every git call skillshare makes during install runs against a directory it owns, so none of them should inherit a caller's repository variables.

Workaround

Clear the variables before calling skillshare:

while read -r name; do unset "$name"; done < <(git rev-parse --local-env-vars)

Activity

  1. self-assigned this
    on Nov 11, 2026
  2. added
    bug
    on Nov 11, 2026
  3. runkids commented on Nov 11, 2026

    @runkids
    Owner

    Thanks for tracking this down, and for the repro and the workaround. Sorry it cost you a working tree.

    The fix is in #854. skillshare now drops GIT_DIR, GIT_WORK_TREE and the other repository variables from every git command it runs, so install, update and push always work on their own directories. It goes out with the next release; until then, your unset loop is the right workaround.

    If you hit anything else from hooks, please open a new issue.

  4. added a commit that references this issue on Nov 12, 2026
    828ba93
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions