diff options
author | Teddy Wing | 2021-06-25 00:58:18 +0200 |
---|---|---|
committer | Teddy Wing | 2021-06-25 00:58:18 +0200 |
commit | bf189958d498255e486455e803d93b5e8de7539e (patch) | |
tree | c765dcee5de2818c27f7c1b8150dae56219dc4d5 /src | |
parent | f3d2cee56389bb41fd539137358eb9dbc884c49f (diff) | |
download | reflectub-bf189958d498255e486455e803d93b5e8de7539e.tar.bz2 |
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
Diffstat (limited to 'src')
-rw-r--r-- | src/main.rs | 19 |
1 files changed, 19 insertions, 0 deletions
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<P: AsRef<Path>>( &repo_path, &updated_repo.default_branch, )?; + + repo_cgitrc_set_defbranch(&repo_path, &updated_repo.default_branch)?; } } @@ -395,6 +401,19 @@ fn set_agefile_time<P: AsRef<Path>>( Ok(()) } +/// Set the default CGit branch in the repository's "cgitrc" file. +fn repo_cgitrc_set_defbranch<P: AsRef<Path>>( + 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<P: AsRef<Path>>( repo_path: P, |