Skip to content

GitInput: Determine default branch for repository#1657

Open
mweinelt wants to merge 1 commit intomasterfrom
git-default-branch
Open

GitInput: Determine default branch for repository#1657
mweinelt wants to merge 1 commit intomasterfrom
git-default-branch

Conversation

@mweinelt
Copy link
Copy Markdown
Member

@mweinelt mweinelt commented Apr 12, 2026

Up until now when no branch was defined the Git Plugin hardcoded the master branch.

Now we try resolving the default branch with git ls-remote and allow a configurable fallback branch, that can be master or anything else.

Tested!

Closes: #325

Comment thread subprojects/hydra/lib/Hydra/Plugin/GitInput.pm Outdated
@mweinelt mweinelt force-pushed the git-default-branch branch from 7be311a to cb021ed Compare April 21, 2026 15:23
Up until now when no branch was defined the Git Plugin hardcoded the
master branch.

Now we try resolving the default branch with git ls-remote and allow
a configurable fallback branch, that can be master or anything else.
@mweinelt
Copy link
Copy Markdown
Member Author

mweinelt commented Apr 21, 2026

starting evaluation of jobset ‘nixos-mailserver:.jobsets (jobset#43)’ (last checked 39 s ago)
(nixos-mailserver:.jobsets) Fetching input `decl` (git) https://gitlab.com/simple-nixos-mailserver/nixos-mailserver
checking out Git branch main from https://gitlab.com/simple-nixos-mailserver/nixos-mailserver
Initialized empty Git repository in /tmp/git-checkout-tmp-pvfWa3Qd/source/.git/
From /var/lib/hydra/scm/git/e772881f93683bcbbf09c2f3678b8c329ac0aa377ec18540e20cf8cdf013a6e6
 * branch            main       -> FETCH_HEAD
 * [new branch]      main       -> origin/main
Switched to a new branch 'fetchgit'
removing `.git'...
hash is 20059ba4f6ebd93275667aa2db2d6452fd183762713f060a57ad55b330af5a9a
path is /nix/store/2vdfq8d0awib7sqqbya0vmmcfdcimdic-source

Tested and successfully pulls main (the default branch on nixos-mailserver) without any branch specified or any specific configuration.

my $cfg = $main_config->{$CONFIG_SECTION};
# default values
my $values = {
fallback_branch => "master",
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default_branch?


# Determine a branch to check out, if none is explicitly defined
if (!defined $branch) {
$branch = _getDefaultBranch($uri) // $cfg->{fallback_branch} // "master";
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or die here, if none can be determined?

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

Successfully merging this pull request may close these issues.

Git repository input should fetch the default branch by default

1 participant