On Windows, when calling git_repository_init_ext for a repo that doesn't exist, if you specify the working directory in the options and it is the same as the the repository directory, the call fails. If you make the same call but without specifying the working directory, the call succeeds.
Previous version used worked as expected.
Accepted that supplying the working directory in this scenario is unnecessary and I have changed our client code to do so, though this does look to be a regression.
Reproduction steps
// GitFaultDemo <repo-folder>. E.g. GitFaultDemo "c:\users\myusername\myrepo"
#include <stdio.h>
#include <stdlib.h>
#include <git2.h>
int main(int argc, char* argv[])
{
const char* repo_path = argv[1];
int status;
git_repository* repo = NULL;
git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT;
status = git_libgit2_init();
if (status < 0)
{
fprintf(stderr, "Failed to initialize libgit2: %d\n", status);
exit(EXIT_FAILURE);
}
opts.flags |= GIT_REPOSITORY_INIT_MKPATH;
opts.description = "Initialize repository";
// With this (redundant) line, the call fails on Windows.
opts.workdir_path = repo_path;
status = git_repository_init_ext(&repo, repo_path, &opts);
if (status < 0)
{
fprintf(stderr, "Failed to initialize repository: %d\n", status);
exit(EXIT_FAILURE);
}
}
If you comment out the specified line, the call works correctly.
Expected behavior
The repo is created and a valid status is returned
Actual behavior
-1 is returned
Version of libgit2 (release number or SHA1)
Not working: v1.8.0
Last working: v1.6.4
Operating system(s) tested
Windows Professional 10/Server 2022
Using vcpkg
Diagnosis
I stepped through to see why it was failing and it looks to me like it was failing because
repo_init_directories is not setting the option flag GIT_REPOSITORY_INIT__NATURAL_WD
The flag is not being set because the test on line 2747 (repository.c) fails because repo_path has forward slashes and wd_path has back slashes.
Possibly all that is needed is a call to git_fs_path_mkposix(wd_path->ptr) after line 2726.
On Windows, when calling git_repository_init_ext for a repo that doesn't exist, if you specify the working directory in the options and it is the same as the the repository directory, the call fails. If you make the same call but without specifying the working directory, the call succeeds.
Previous version used worked as expected.
Accepted that supplying the working directory in this scenario is unnecessary and I have changed our client code to do so, though this does look to be a regression.
Reproduction steps
If you comment out the specified line, the call works correctly.
Expected behavior
The repo is created and a valid status is returned
Actual behavior
-1 is returned
Version of libgit2 (release number or SHA1)
Not working: v1.8.0 Last working: v1.6.4
Operating system(s) tested
Windows Professional 10/Server 2022 Using vcpkg
Diagnosis
I stepped through to see why it was failing and it looks to me like it was failing because
git_fs_path_mkposix(wd_path->ptr)
after line 2726.