From 98ef161268ef3af40618fe1bb52d0c8721fcc0b8 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Wed, 23 Jun 2021 01:24:28 +0200 Subject: git::mirror(): Fix setting repository description on Linux After a bunch of investigation, first with a small 'git2' project, then a 'libgit2-sys' project, then a 'libgit2' C project, I finally discovered why setting the description worked on Mac OS but not on Linux. Turning on the `GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE` repository init flag caused the default description to be used instead of the custom description passed in the init. Turn off the flag to allow us to set the description on Linux. Here is the source of the test builds I made: git2 test: use git2; fn main() { let path = "/tmp/test-repo"; let description = "the description"; let repo = git2::Repository::init_opts( path, &git2::RepositoryInitOptions::new() .bare(true) .external_template(false) .description(description), ).unwrap(); } libgit2-sys test: use libgit2_sys; use std::ffi::CString; use std::ptr; fn main() { let _ = unsafe { libgit2_sys::git_libgit2_init() }; let mut repo = ptr::null_mut(); let path = CString::new("/tmp/test-repo").unwrap(); let description = CString::new("Test").unwrap(); let mut opts = libgit2_sys::git_repository_init_options { version: libgit2_sys::GIT_REPOSITORY_INIT_OPTIONS_VERSION, flags: libgit2_sys::GIT_REPOSITORY_INIT_MKDIR as u32 | libgit2_sys::GIT_REPOSITORY_INIT_MKPATH as u32 | libgit2_sys::GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE as u32, mode: 0, workdir_path: ptr::null(), description: description.as_ptr(), template_path: ptr::null(), initial_head: ptr::null(), origin_url: ptr::null(), }; let error = unsafe { libgit2_sys::git_repository_init_ext( &mut repo, path.as_ptr(), &mut opts, ) }; dbg!(&error); } libgit2 test: #include #include "git2.h" int main() { int error; const git_error *lg2err; error = git_libgit2_init(); if (error <= 0) { printf("git_libgit2_init error: %d\n", error); } git_repository *repo = NULL; git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; /* Customize options */ opts.flags |= GIT_REPOSITORY_INIT_MKPATH; /* mkdir as needed to create repo */ opts.flags |= GIT_REPOSITORY_INIT_MKDIR; /* opts.flags |= GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; */ opts.description = "Custom test description"; error = git_repository_init_ext(&repo, "/tmp/test-repo", &opts); printf("git_repository_init_ext error: %d\n", error); lg2err = git_error_last(); if (lg2err != NULL) { printf("%s\n", lg2err->message); } } --- src/git.rs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/git.rs b/src/git.rs index 6a2f153..ac950e5 100644 --- a/src/git.rs +++ b/src/git.rs @@ -49,6 +49,11 @@ pub fn mirror>( path, &git2::RepositoryInitOptions::new() .bare(true) + + // On Linux, using the external template prevents the custom + // description from being added. It doesn't make a difference on + // Mac OS. + .external_template(false) .description(description), )?; -- cgit v1.2.3