dune-release icon indicating copy to clipboard operation
dune-release copied to clipboard

Issues when releasing from a git worktree

Open reynir opened this issue 3 years ago • 3 comments

I encountered some warts when using dune-release from a git worktree. Unfortunately, I closed the shell I was using in the subtree so I can't paste all output.

When I ran dune-release opam submit I got an error from git complaining about the index. Indeed, I had a merge conflict that I hadn't committed yet. The command seemed a bit odd with the worktree. Not sure if this is a bug.

reynir@spurv:~/workspace/ocaml-ssh-agent$ git worktree add ../fix-ssh-agent master 
Preparing worktree (checking out 'master')
HEAD is now at 3e5b8ff732 Update example to cmdliner.1.1.0

After I fixed this merge conflict I ran dune-release opam submit and it worked, but while the files in the directory seemed untouched the git worktree was checked out as release-ssh-agent-v0.3.1, the opam-repository release branch. Git status in the worktree complained about all the files deleted in packages/ and untracked files that were files from my project.

reynir@spurv:~/workspace/ocaml-ssh-agent$ git worktree list
/home/reynir/workspace/ocaml-ssh-agent  6061294366 [ssh-ed25519]
/home/reynir/workspace/fix-ssh-agent    7610b693a3 [release-ssh-agent-v0.3.1]

reynir avatar Apr 01 '22 13:04 reynir

Today I experienced another error when publishing ocaml-tar 2.5.0 from a git worktree:

$ dune-release
[...SNIP...]
[-] Submitting 
[-] Preparing pull request to ocaml/opam-repository
[-] Fetching https://github.com/ocaml/opam-repository.git#master
[-] Checking out a local release-tar-v2.5.0 branch
dune-release: [ERROR] Exit code 1 from command
    `git --git-dir /home/reynir/workspace/ocaml-tar/.git/worktrees/tar.2.5.x
       --work-tree /home/reynir/workspace/ocaml-tar/.git/worktrees/ checkout
       --quiet -b release-tar-v2.5.0 2e19a179ef81238d103d785882a06681434d8e88`:
  error: Your local changes to the following files would be overwritten by checkout:
  	.gitattributes
  	.gitignore
  	CHANGES.md
  	README.md
  Please commit your changes or stash them before you switch branches.
  error: The following untracked working tree files would be overwritten by checkout:
  	CONTRIBUTING.md
  	COPYING
  	packages/0install-gtk/0install-gtk.2.15.2/opam
  	packages/0install-gtk/0install-gtk.2.16/opam
  	packages/0install-gtk/0install-gtk.2.17/opam
  	packages/0install-gtk/0install-gtk.2.18/opam
  	packages/0install-solver/0install-solver.2.17/opam
  	packages/0install-solver/0install-solver.2.18/opam
  	packages/0install/0install.2.10/files/0install.install
  	packages/0install/0install.2.10/opam
  	packages/0install/0install.2.11/files/0install.install
  	packages/0install/0install.2.11/opam
  	packages/0install/0install.2.12.1/files/0install.install
  	packages/0install/0install.2.12.1/opam
  	packages/0install/0install.2.12.3/files/0install.install
  	packages/0install/0install.2.12.3/opam
  	packages/0install/0install.2.12/files/0install.install
  	packages/0install/0install.2.12/opam
  	packages/0install/0install.2.14.1/opam
  	packages/0install/0install.2.14/opam
  	packages/0install/0install.2.15.1/opam
  	packages/0install/0install.2.15.2/opam
  	packages/0install/0install.2.16/opam
  	packages/0install/0install.2.17/opam
  	packages/0install/0install.2.18/opam
  	packages/0install/0install.2.6.2/files/0install.install
  	packages/0install/0install.2.6.2/files/gui_gtk_dir.patch
  	packages/0install/0install.2.6.2/opam
  	packages/0install/0install.2.8/files/0install.install
  	packages/0install/0install.2.8/files/gui_gtk_dir.patch
  	packages/0install/0install.2.8/opam
  	packages/0install/0install.2.9.1/files/0install.install
  	packages/0install/0install.2.9.1/opam
  	packages/ANSITerminal/ANSITerminal.0.6.2/opam
  	packages/ANSITerminal/ANSITerminal.0.6.3/opam
  	packages/ANSITerminal/ANSITerminal.0.6.4/opam
  	packages/ANSITerminal/ANSITerminal.0.6.5/opam
  	packages/ANSITerminal/ANSITerminal.0.6/opam
  	packages/ANSITerminal/ANSITerminal.0.7/opam
  	packages/ANSITerminal/ANSITerminal.0.8.1/opam
  	packages/ANSITerminal/ANSITerminal.0.8.2/opam
  	packages/ANSITerminal/ANSITerminal.0.8.3/opam
  	packages/ANSITerminal/ANSITerminal.0.8.4/opam
  	packages/ANSITerminal/ANSITerminal.0.8.5/opam
  	packages/ANSITerminal/ANSITerminal.0.8/opam
  	packages/BetterErrors/BetterErrors.0.0.1/opam
  	packages/CamlGI/CamlGI.0.6/files/CamlGI.install
  	packages/CamlGI/CamlGI.0.6/opam
  	packages/Camldiets/Camldiets.0.2/opam
  	packages/DAGaml/DAGaml.0.01/opam
  	packages/DAGaml/DAGaml.0.02/opam
  	packages/DrawGrammar/DrawGrammar.0.1.0/opam
  	packages/DrawGrammar/DrawGrammar.0.2.0/opam
  	packages/DrawGrammar/DrawGrammar.0.2.1/opam
  	packages/DrawGrammar/DrawGrammar.0.2.2/opam
  	packages/FPauth-core/FPauth-core.1.0.0/opam
  	packages/FPauth-responses/FPauth-responses.1.0.0/opam
  	packages/FPauth-strategies/FPauth-strategies.1.0.0/opam
  	packages/FPauth/FPauth.1.0.0/opam
  	packages/FrontC/FrontC.3.4.1/files/FrontC.install
  	packages/FrontC/FrontC.3.4.1/files/META
  	packages/FrontC/FrontC.3.4.1/files/opam.patch
  	packages/FrontC/FrontC.3.4.1/opam
  	packages/FrontC/FrontC.3.4.2/files/FrontC.install
  	packages/FrontC/FrontC.3.4.2/files/META
  	packages/FrontC/FrontC.3.4.2/files/opam.patch
  	packages/FrontC/FrontC.3.4.2/opam
  	packages/FrontC/FrontC.3.4.3-1/files/FrontC.install
  	packages/FrontC/FrontC.3.4.3-1/files/fix-cmxs-cmx.patch
  	packages/FrontC/FrontC.3.4.3-1/opam
  	packages/FrontC/FrontC.3.4.3/files/FrontC.install
  	packages/FrontC/FrontC.3.4.3/opam
  	packages/FrontC/FrontC.3.4/files/FrontC.install
  	packages/FrontC/FrontC.3.4/files/META
  	packages/FrontC/FrontC.3.4/files/opam.patch
  	packages/FrontC/FrontC.3.4/opam
  	packages/FrontC/FrontC.4.0.0/opam
  	packages/FrontC/FrontC.4.1.0/opam
  	packages/GT/GT.0.3.0/opam
  	packages/GT/GT.0.4.0/opam
  	packages/GT/GT.0.4.1/opam
  	packages/GT/GT.0.4.2/opam
  	packages/GT/GT.0.5.0/opam
  	packages/GT/GT.0.5.1/opam
  	packages/General/General.0.1.0/opam
  	packages/General/General.0.2.0/opam
  	packages/General/General.0.4.0/opam
  	packages/General/General.0.5.0/opam
  	packages/General/General.0.6.0/opam
  	packages/General/General.0.7.0/opam
  	packages/GuaCaml/GuaCaml.0.02/opam
  	packages/GuaCaml/GuaCaml.0.03.01/opam
  	packages/GuaCaml/GuaCaml.0.03/opam
  	packages/GuaCaml/GuaCaml.0.04/opam
  	packages/GuaCaml/GuaCaml.0.05/op
  Aborting

reynir avatar Jun 06 '23 07:06 reynir

I encountered the same error again and spent a few minutes investigating the error. What I have found is an incorrect assumption of the relationship between $GIT_DIR and $GIT_WORK_TREE:

https://github.com/tarides/dune-release/blob/0baf5f2410d8f3a17608374bbede5e3fb7f3c3d9/lib/vcs.ml#L55

For a git repository in /foo/ and a git worktree /bar/ we get /foo/.git/worktrees/bar when running git rev-parse --git-dir inside /bar/. Thus the current code checks out the code in /foo/.git/worktrees/ which is untracked by git and results in a mess.

Further looking into the code it seems $DUNE_RELEASE_LOCAL_REPO isn't actually used (besides for misleading error messages). Instead, opam-repository is checked out within the repository where the release is being made. https://github.com/tarides/dune-release/blob/0baf5f2410d8f3a17608374bbede5e3fb7f3c3d9/lib/opam.ml#L107-L132

reynir avatar Sep 07 '23 13:09 reynir

Thanks for the investigation, these are pretty good insights and should be a big help to solve this issue!

Leonidas-from-XIV avatar Sep 08 '23 08:09 Leonidas-from-XIV