Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues when releasing from a git worktree #439

Open
reynir opened this issue Apr 1, 2022 · 3 comments
Open

Issues when releasing from a git worktree #439

reynir opened this issue Apr 1, 2022 · 3 comments

Comments

@reynir
Copy link

reynir commented Apr 1, 2022

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
Copy link
Author

reynir commented Jun 6, 2023

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
Copy link
Author

reynir commented Sep 7, 2023

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:

let git_work_tree (_, _, dir) = Cmd.(v "--work-tree" % p Fpath.(parent dir))

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.

dune-release/lib/opam.ml

Lines 107 to 132 in 0baf5f2

let prepare_repo () =
App_log.status (fun l ->
l "Fetching %a" Text.Pp.url (upstream ^ "#" ^ remote_branch));
Vcs.run_git_quiet repo ~dry_run ~force:true
Cmd.(v "fetch" % upstream % remote_branch)
>>= fun () ->
Vcs.run_git_string repo ~dry_run ~force:true ~default:(Sos.out D.fetch_head)
Cmd.(v "rev-parse" % "FETCH_HEAD")
>>= fun id ->
(* make a branch *)
let delete_branch () =
if not (Vcs.branch_exists ~dry_run:false repo branch) then Ok ()
else
match
Vcs.run_git_quiet repo ~dry_run ~force:true
Cmd.(v "checkout" % "master")
with
| Ok () ->
Vcs.run_git_quiet repo ~dry_run ~force:true
Cmd.(v "branch" % "-D" % branch)
| Error _ ->
let out = OS.Cmd.run_out Cmd.(git % "status") in
OS.Cmd.out_lines out >>= fun (out, _) ->
R.error_msgf "git checkout in %a failed:\n %s" Fpath.pp local_repo
(String.concat ~sep:"\n" out)
in

@Leonidas-from-XIV
Copy link
Member

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

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

No branches or pull requests

2 participants