Skip to content

cabal get: check out the tag without moving the cloned branch - #12644

Open
swinilohani616-dot wants to merge 3 commits into
haskell:masterfrom
swinilohani616-dot:cabal-get-keep-branch
Open

swinilohani616-dot wants to merge 3 commits into
haskell:masterfrom
swinilohani616-dot:cabal-get-keep-branch

Conversation

@swinilohani616-dot

Copy link
Copy Markdown
Contributor

Fixes #10278.

When a package's source-repository has a tag:, cabal get -s clones the repo and then runs
git reset --hard <tag>. The files end up at the tag, which is right, but the reset also drags the branch you
just cloned back to that tag. So you're sitting on main, except your main now points at an old release and
git tells you it's behind origin/main. That's not what anyone expects after a fresh clone.

I've changed that second step to git checkout --detach <tag>. You still get exactly the tag's files, but the
branch is left alone and keeps matching the remote. This only affects the clone cabal get does.
source-repository-package checkouts go through a different code path, so they behave the same as before.

The issue also floats making branch: and tag: mutually exclusive and changing what -d means. Those felt
like bigger design questions, so I kept this PR to the bug itself, but I'm happy to pick them up separately if
people want.

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
  • Manual QA notes:
    1. Make a git repo with a commit tagged v1 and a newer commit on main.
    2. Make a package whose source-repository this points at it with tag: v1 (adding branch: main is fine
      too), and put its sdist in a local repository.
    3. Run cabal get <pkg> --source-repository=this, then git status inside the clone.
      Without this change you'll see main...origin/main [behind 1]. With it, HEAD should be detached at
      v1 and main should still match origin/main.
  • Tests have been added: a unit test in UnitTests.Distribution.Client.VCS that clones at a tag and checks
    that the files are at the tag while the cloned branch still matches the source repo.

When cloning a git source-repository that has a tag, cabal get -s ran
"git reset --hard <tag>" after cloning. That moved the branch it had
just cloned back to the tag, so the local branch no longer matched the
remote (and if a branch: was given too, that branch was the one moved).

Check the tag out as a detached HEAD instead, so the working tree is at
the tag and the cloned branch stays where it is on the remote. This only
affects vcsCloneRepo, which is used by cabal get; syncing
source-repository-package checkouts is unchanged.

Fixes haskell#10278
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.

cabal get should not reset the default branch to the given tag

1 participant