libgit2 / libgit2/pygit2

Staged area modified after cross branch checkout

Aperta
#1,355 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Python
Stelle
1.7k
Fork
408
Merge medio
2g 57m
PR unite (30g)
7

Descrizione

I created two branches with commits like this:

Image

Then I call checkout to switch the branch from old_master to master. Somehow, the cached area is updated after checkout:

Image

Here's the code toe reproduce

import pathlib

import pygit2


def test_checkout(tmp_path: pathlib.Path):
    repo_dir = tmp_path

    git_author = pygit2.Signature(name="foo", email="foo@bar.com")
    repo = pygit2.init_repository(str(repo_dir))
    workdir = pathlib.Path(repo.workdir)
    readme = workdir / "README.md"

    readme.write_text("commit0")
    index = repo.index
    index.add(readme.relative_to(workdir).as_posix())
    index.write()
    tree = index.write_tree()
    commit0 = repo.create_commit("HEAD", git_author, git_author, "commit0", tree, [])

    master_branch = repo.branches.local["master"]
    old_master_branch = repo.branches.local.create("old_master", master_branch.peel())

    readme.write_text("commit1")
    index = repo.index
    index.add(readme.relative_to(workdir).as_posix())
    index.write()
    tree = index.write_tree()
    repo.create_commit(repo.head.name, git_author, git_author, "commit1", tree, [commit0])

    repo.checkout(old_master_branch)
    readme.write_text("commit2")
    index = repo.index
    index.add(readme.relative_to(workdir).as_posix())
    index.write()
    tree = index.write_tree()
    repo.create_commit(repo.head.name, git_author, git_author, "commit2", tree, [commit0])

    repo.checkout(master_branch)
    # the staged area should be empty after checkout
    assert not list(repo.index)

I tried it with git checkout master and it works fine without changing the staged area.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo il riproduttore test_checkout fornito e analizza il comportamento di repo.checkout e repo.index durante i due cambi di branch. Confronta l’indice in staging dopo essere tornato a master con lo stato vuoto previsto e verifica il risultato rispetto al comportamento descritto di git checkout.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
git, python
Ambito
tooling
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.