Skip to content

[feature request] fetch branch refs before git operations #1183

@ElleNajt

Description

@ElleNajt

Feature request:

Currently, changing the branch name in the recipe from the branch it was initialized with causes upgrade to fail with error:

  $ git rev-parse --verify master
      fatal: Needed a single revision
      [Return code: 128]
      $ cd /home/username/.emacs.d/.local/straight/repos/example-repo/
      $ git branch --track -- master origin/master
      fatal: the requested upstream branch 'origin/master' does not exist
      hint:
      hint: If you are planning on basing your work on an upstream
      hint: branch that already exists at the remote, you may need to
      hint: run "git fetch" to retrieve it.
      hint:
      hint: If you are planning to push out a new local branch that
      hint: will track its remote counterpart, you may want to use
      hint: "git push -u" to set the upstream config as you push.
      hint: Disable this message with "git config advice.setUpstreamFailure false"
      [Return code: 128]

Instead, I think should set up tracking for the new branch, fetch, and then attempt the switch.

Detailed Directions to reproduce

Initialize a repository with a branch and run straight (in my case doom upgrade)

(package! example-repo
  :recipe (:host github
           :repo "example-user/example-repo"
           :branch "Development"))

Then change the recipe to :

(package! example-repo
  :recipe (:host github
           :repo "example-user/example-repo"
           ;; :branch "Development"
           ))

Then rerunning straight will give the error mentioned above:

   .git
      [Return code: 0]
      $ cd /home/username/.emacs.d/.local/straight/repos/example-repo/
      $ git ls-files --unmerged
      [Return code: 0]
      $ cd /home/username/.emacs.d/.local/straight/repos/example-repo/
      $ git -c status.branch\=false status --short
      [Return code: 0]
      $ cd /home/username/.emacs.d/.local/straight/repos/example-repo/
      $ git rev-parse --verify master
      fatal: Needed a single revision
      [Return code: 128]
      $ cd /home/username/.emacs.d/.local/straight/repos/example-repo/
      $ git branch --track -- master origin/master
      fatal: cannot set up tracking information; starting point 'origin/master' is not a branch
      [Return code: 128]

When I go into the repository, I see that only the development branch is being tracked:

username@computer:~/.emacs.d/.local/straight/repos/example-repo/ > git branch -a
* Development
  remotes/origin/Development

Work around

I run this in the repository inside /.local/straight :

git remote set-branches origin "*"
git fetch

and I can see with git branch -a that the master branch is being tracked as well, and now the recipe upgrades properly regardless of changing the branch back and forth (although I have to rerun that code if a new branch in the remote appears that I want in the recipe).

It also works to delete the repository and use the new recipe from scratch, but this needs to be done with each recipe switch, so isn't a good work around.

Requested feature:

Based on this, it seems like it would be useful for straight to run something like this before trying to upgrade:

git remote set-branches origin $BRANCH_NAME
# where BRANCH_NAME is obtained from the recipe or pulled from something like git remote show origin,
# or however straight knew to look for the master branch in the example above
git fetch

Version information

  • Emacs version: GNU Emacs 29.4
  • Operating system: Nixos 24.11pre-git (Vicuna)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions