0

I'm using stack with hpack so that .cabal file is generated from hpack's package.yaml. Often times as I want to switch branch I struggle with constantly changing .cabal file.

  • I run git restore *.cabal. Working tree is in unstaged state.
  • Immediately after I run git switch branch but get

error: Your local changes to the following files would be overwritten by checkout: Package.cabal

  • The error message is correct as .cabal has changed and now there are uncommited changes. I didn't observe the exact circumstances but here my Paths_Package differs between the branches.

Why does this happen? Does stack rerun hpack on every modification? Isn't it enough to recompute .cabal before build?

This behaviour is frustrating and how I'm solving it for now is running as a single command:

git restore *.cabal && git switch branch

Above works. What does it tell about the moment of recomputation?

Important

Final thing is that the recomputation could be triggered from different source. I don't remember from where it comes from, but my terminal displays ghc version for the stack project on the side. My only idea on what triggers this is stack --bash-completion-script. I have default manjaro zsh config with stack from aur. Is there some deamon waiting to stage some changes right when before switch?

Thanks in advance!

zaabson
  • 151
  • 12
  • Why do you version control the `.cabal` file if it's auto-generated from `package.yaml`? – leftaroundabout Feb 25 '22 at 13:44
  • @leftaroundabout I think you're touching an old [discussion](https://github.com/commercialhaskell/stack/issues/5210). I have no strong feelings here and could just untrack .cabal (simmilarly as I can still be using the trick from my post). But I think the question remains as both solutions are workarounds. – zaabson Feb 25 '22 at 16:09

0 Answers0