haskell / haskell/cabal

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

Open
#10,278 5 comments 0 reactions 0 assignees View on GitHub
attention: pr-welcome cabal-install: cmd/get newcomer type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

Currently, having a package that declares the following `source-repository` stanza in the available repositories (hackage):
```
source-repository this
type: git
location:
tag:
branch:
```
When one runs `cabal get -sthis -d` will perform the following sequence of commands:
```
(cd somedir && git clone --branch )

if [ -n ]; then
(cd somedir/pkg && git reset --hard --)
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 --branch ` 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 -sthis -d` will clone the repo in `./somedir` and not in `./somedir/reponame`. This can be achieved by invoking `git clone --branch `

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.