Skip to content

Draft: feat(mr/checkout): Update fetch ref even if not fast forward

Austin Phillips requested to merge austyp/cli:1379-fix-mr-co-fetch-non-ff into main

Description

Fetch remote branches using the + symbol ref prefix so that local branch references are updated even if they are not fast-forward. This allows use of mr checkout for on branches which may not be fast forward such as when a remote rebase of an existing mr occurs.

Use of +: refspec for the git fetch rather than : matches git's default fetch behaviour when tracing remote branches.

This change is especially useful in rebase heavy workflows where MRs are rebased in Gitlab using the Rebase MR button or when changes are rebased by other developers, and glab mr checkout is used to retrieve the latest MR branch contents.

Related Issues

Partially resolves #1379 (glab mr checkout XXXXX fails if your local copy of the branch is behind the remote, and a fast-forward isn't possible.)

How has this been tested?

Tested against a corporate Gitlab server on a repo configured with fast-forward merges.

  1. Submitted MR!1 from branch/x from current repo with main target branch
  2. Checkout out main and pushed new commits to on main branch to remote
  3. Pressed Rebase button on MR!1 in Gitlab Web UI to reparent branch/x on remote
  4. Used glab mr co 1 locally to fetch and download MR!1 containing branch/x with remote branch/x which is not fast forward from local branch/x
  5. Verified that origin/branch/x matches local branch/x

Without this change, step 4 fails due to local branch/x not being fast-forward to origin/branch/x.

Types of changes

  • New feature (non-breaking change which adds functionality)

Merge request reports