Subject: Re: git remote set-head automatically

From: Jeff King <[email-masked]>
Date: Tue, 19 Nov 2024 13:44:04 -0500

On Tue, Nov 19, 2024 at 12:06:21PM -0500, Caleb Cushing wrote:

> A little more progress on what I'm going to have to do, github action,
> without set-head the ref/HEAD isn't present
> 
> - uses: actions/checkout@v4
>   with:
>     ref: ${{ github.event.workflow_run.head_branch}}
>     filter: "blob:none"
>     fetch-depth: 0
> - run: git remote set-head origin --auto # fixes otherwise the cat
> will not find a file

We do create the HEAD symref in clone by default, but IIRC
actions/checkout does a more limited clone with --depth and
--single-branch.

The separate set-head should work, but it is a shame that it will have
to hit the server for a second request.

You might look for options in actions/checkout to change the way it
invokes Git. Though I suspect there might not be a way to trigger
git-clone to do a single-branch clone _and_ create the HEAD symref. So
you may be stuck with the two calls.

> - run: cat .git/refs/remotes/origin/HEAD

Don't access the file directly; it will break if the ref storage format
changes. Use "git symbolic-ref refs/remotes/origin/HEAD" instead.

(Not sure if this was just illustrative or what you are planning to do
in a real CI job).

-Peff