diff options
author | Teddy Wing | 2021-06-23 01:24:28 +0200 |
---|---|---|
committer | Teddy Wing | 2021-06-23 01:24:28 +0200 |
commit | 98ef161268ef3af40618fe1bb52d0c8721fcc0b8 (patch) | |
tree | fbe60a6a82558dcaed9fe41b1b3ca13b5551c018 | |
parent | fc9a7a761571e8508af0a1a224e6f079132dad7d (diff) | |
download | reflectub-98ef161268ef3af40618fe1bb52d0c8721fcc0b8.tar.bz2 |
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 <stdio.h>
#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);
}
}
-rw-r--r-- | src/git.rs | 5 |
1 files changed, 5 insertions, 0 deletions
@@ -49,6 +49,11 @@ pub fn mirror<P: AsRef<Path>>( 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), )?; |