GNU bug report logs - #49252
[PATCH] Channels defaulting to HEAD instead of ‘master’

Previous Next

Package: guix-patches;

Reported by: Ludovic Courtès <ludo <at> gnu.org>

Date: Mon, 28 Jun 2021 12:57:01 UTC

Severity: normal

Tags: patch

Full log


View this message in rfc822 format

From: Kyle Meyer <kyle <at> kyleam.com>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: Ricardo Wurmus <rekado <at> elephly.net>, 49252 <at> debbugs.gnu.org
Subject: [bug#49252] [PATCH] Channels defaulting to HEAD instead of ‘master’
Date: Tue, 10 Aug 2021 20:34:58 -0400
Ludovic Courtès writes:

> Right.  We can add the missing procedures in Guile-Git, but in the
> meantime, maybe we could create .git/refs/origin/HEAD “by hand”?

Yep, for the default branch $NAME, "ref: refs/remotes/origin/$NAME\n"
can be written to .git/refs/origin/HEAD.

With respect to getting the default branch, I said in my last message
that I thought it'd be possible to glean the target from the remote-ls
output.  To flesh that out a bit:

--8<---------------cut here---------------start------------->8---
(use-modules
 (git)
 (system foreign))

(define origin (remote-lookup (repository-open ".") "origin"))
(remote-connect origin)

(define head (car (remote-ls origin)))

(define target-pt
  (make-pointer
   ((record-accessor (record-type-descriptor head) 'symref-target)
    head)))

(if (not (null-pointer? target-pt))
    (display (pointer->string target-pt)))  ;; => refs/heads/master
--8<---------------cut here---------------end--------------->8---

And that looks like it matches what libgit2's
git_remote_default_branch() does for the non-guessing case (see below),
so stopping there may be sufficient for a compatibility kludge.

--8<---------------cut here---------------start------------->8---
	if ((error = git_remote_ls(&heads, &heads_len, remote)) < 0)
		goto done;

	if (heads_len == 0 || strcmp(heads[0]->name, GIT_HEAD_FILE)) {
		error = GIT_ENOTFOUND;
		goto done;
	}

	if ((error = git_buf_sanitize(out)) < 0)
		return error;

	/* the first one must be HEAD so if that has the symref info, we're done */
	if (heads[0]->symref_target) {
		error = git_buf_puts(out, heads[0]->symref_target);
		goto done;
	}

	/*
	 * If there's no symref information, we have to look over them
	 * and guess. We return the first match unless the default
	 * branch is a candidate. Then we return the default branch.
*/--8<---------------cut here---------------end--------------->8---




This bug report was last modified 3 years and 307 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.