From bf189958d498255e486455e803d93b5e8de7539e Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 25 Jun 2021 00:58:18 +0200 Subject: main: If the default branch is not "master", set cgitrc defbranch In order for CGit to know that the repository uses a default branch that isn't "master", we need to set the `defbranch` setting in 'cgitrc'. The mtime is read from either the "master" ref or the ref specified with `defbranch`: https://git.zx2c4.com/cgit/tree/ui-repolist.c?id=5258c297ba6fb604ae1415fbc19a3fe42457e49e#n56 --- src/main.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.rs b/src/main.rs index a28eac2..0cf4328 100644 --- a/src/main.rs +++ b/src/main.rs @@ -259,6 +259,10 @@ where ))?; } + if repo.default_branch != "master" { + repo_cgitrc_set_defbranch(&clone_path, &repo.default_branch)?; + } + update_mtime(&clone_path, &repo)?; Ok(()) @@ -284,6 +288,8 @@ fn update>( &repo_path, &updated_repo.default_branch, )?; + + repo_cgitrc_set_defbranch(&repo_path, &updated_repo.default_branch)?; } } @@ -395,6 +401,19 @@ fn set_agefile_time>( Ok(()) } +/// Set the default CGit branch in the repository's "cgitrc" file. +fn repo_cgitrc_set_defbranch>( + repo_path: P, + default_branch: &str, +) -> anyhow::Result<()> { + repo_cgitrc_append( + &repo_path, + &format!("defbranch={}", default_branch), + )?; + + Ok(()) +} + /// Append `config` to the repo-local "cgitrc" file. fn repo_cgitrc_append>( repo_path: P, -- cgit v1.2.3