--changed refuses a repository with no commit and counts .spackle state files as changed

Aberta
#126 0 comentários 0 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
70/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
git, go

Direção de pesquisa

Start with ChangedUncommitted in internal/gitx/gitx.go and the HasTracked precheck and error wording in changedSince in internal/engine/diffscan.go; reproduce both cases in a fresh git init and in a repo with one commit. The state directory exclusion can follow the existing IsCleanExcept pathspec approach in internal/mapper/mapper.go. Done means go test ./internal/gitx ./internal/engine passes with the new TestChangedUncommitted cases, and --changed works before the first commit without counting .spackle files.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

bug good first issue severity: low

Summary

The file listing behind --changed has two bugs, and its edge cases have no direct test. It refuses a repository that has no commit yet, and it counts every file of the untracked .spackle/ state directory as a changed file.

Where

  • internal/gitx/gitx.go:294-309 (ChangedUncommitted)
  • internal/engine/diffscan.go:28-49 (changedSince: HasTracked precheck, error wording)
  • internal/engine/diffscan.go:63-71 (keepChanged prints len(changed))
  • internal/mapper/mapper.go:103-111 (the mapper already excludes the state dir with IsCleanExcept)

Details

func ChangedUncommitted(ctx context.Context, dir string) ([]string, error) {
	files, err := changedFiles(ctx, dir, "HEAD")
	...
	out, err := run(ctx, dir, "ls-files", "-z", "--others", "--exclude-standard")
  1. Before the first commit. HEAD does not resolve, so git diff ... HEAD fails with fatal: bad revision 'HEAD' and the scan is refused: run refused: --changed: git could not list the changes against HEAD, exit 2. In a fresh git init with nothing staged, the HasTracked precheck refuses earlier with "has no tracked files", although every file is uncommitted work.
  2. State directory counted. ls-files --others --exclude-standard lists everything under the default state_dir = ".spackle", which sits inside the target and is untracked and not ignored. Ledgers, reports, evidence, map cache files and clones all count as changed files. The lead filter is unaffected (the walk never lists .spackle/), but the note shows a wrong count that grows with every stored run.

Impact

--changed is documented as "a scan before you commit", but it cannot be used for a project's first commit, a common pre-commit-hook case. After the first scan, every --changed run reports an inflated "N changed files" in the terminal, the ledger and every report.

Steps to reproduce

  1. git init x && cd x, create main.go, git add main.go, then spackle scan --changed --provider "" .: refused, exit 2.
  2. In a repository with one commit: spackle scan --provider "" ., edit main.go, then spackle scan --changed --provider "" .. The note says "9 changed files" while git status --porcelain shows only M main.go and ?? .spackle/.

Suggested fix

  • When git rev-parse --verify -q HEAD fails, list git ls-files -z (the index) plus the untracked files instead of diffing against HEAD. In changedSince, skip the HasTracked precheck for --changed and keep ErrNotRepo as the only refusal.
  • Exclude the state directory from both git calls with a pathspec, as IsCleanExcept does (-- . ":(exclude).spackle", using the configured state dir name), or drop entries under it before returning.

Acceptance criteria

  • --changed works before the first commit and treats staged and untracked files as changed.
  • Files under the state directory never appear in the changed set or its count.
  • TestChangedUncommitted in internal/gitx covers: staged-only edit, unstaged edit, deleted file (not listed), git mv rename (new name only), untracked vs ignored, a subdirectory target (paths relative to it), names with spaces and non-ASCII, a clean tree, no commits, and the state directory.
  • A CLI test passes --changed through to the engine, and --changed --since HEAD exits with a usage error.

Getting started

  • Relevant files: internal/gitx/gitx.go, internal/gitx/gitx_test.go, internal/engine/diffscan.go
  • How to run tests: go test ./internal/gitx ./internal/engine

Filed by repo-audit/full-audit at fffef43. Severity: low. Effort: S. audit-key: bug|internal/gitx/gitx.go|ChangedUncommitted

Linguagem predominante
Go
Estrelas
0
Forks
1
Métricas de merge de PRs
Nenhum PR com merge em 30d

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de TMHSDigital/Spackle

Todas as issues de TMHSDigital/Spackle

Issues semelhantes

Mais issues de Go

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.