Skip to content

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

Open
@jasagredo

Description

@jasagredo

Currently, having a package that declares the following source-repository stanza in the available repositories (hackage):

source-repository this
  type: git 
  location: <url>
  tag: <tag>
  branch: <branch>

When one runs cabal get <pkg> -sthis -d<somedir> will perform the following sequence of commands:

(cd somedir && git clone <url> --branch <branch>)

if [ -n <tag> ]; then
  (cd somedir/pkg && git reset --hard <tag> --)
fi

(cd somedir/pkg && git submodule sync --recursive)
(cd somedir/pkg && git submodule update --init --force --recursive)

I would argue that the git reset is just wrong. It will reset whichever branch was cloned to the tag, resulting in a state that disagrees with the git server. My proposal is as follows:

  1. branch and tag should be exclusive. To be precise, they could be merged into either of them or some new name. Either way, only one of those has to/should be provided. Probably ref or rev would be a good name.
  2. Invoke git clone <url> --branch <branch-or-tag> as git can handle tags in that argument.
  3. As a side improvement, the directory provided in -d should be used as the output directory, and not as a parent folder for the clone. This means that using cabal get <pkg> -sthis -d<somedir> will clone the repo in ./somedir and not in ./somedir/reponame. This can be achieved by invoking git clone --branch <branch-or-tag> <url> <somedir>

Note that the same reasoning could apply to source-repository-package as those also allow for branch and tag.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions