简体   繁体   中英

How to initialise a git repository with libgit2

On a Windows XP, 32-bit machine I've cloned the libgit2 repository using

git clone git://github.com/libgit2/libgit2.git trunk

Then I configured from trunk_build_debug for mingw using:

cmake ../trunk -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=-g 

and build-ed it with

make

With this newly build library I'm trying to create a new repository. So I'm using

    error_code = git_repository_init( &repo, path, 0 );
    if ( error_code != 0 )
    {
        const git_error * error = giterr_last();
       /* the text representation:
        ( error == NULL || error->message == NULL ? 
        "(no description)" : 
        error->message )
        */
    }

On first attempt this fails with the error message:

Git error -1: The global file '.config/git/config' doesn't exist: The system cannot find the file specified.

The .git directory is created and I can use git status to query it. Also, I have git installed in Program Files/git and it works just fine. The file that is mentioned does not exist in user directory, that is true. I'm not happy because I can't check the returned error code (the error may be "real").

So I've created an empty file in D:\\Documents and Settings\\User Name.config\\git\\config The .git directory is again created but I get the same -1 error code. This time giterr_last() returns NULL.

Tracing the code in debugger seems to indicate that the library is not happy with my empty file.

However, I think this indicates that I'm doing something wrong. Is there an initialization method? Do I need to create the file and use the git_config_ functions to point the library to it?

BTW, is this the wrong place to ask this? Is there a dedicated forum where I should ask this question?

Thanks


Here is the back trace where the call fails: pastebin It seems that the configure file inside .git directory can't be parsed (not shown in in trace is the 'config_parse()' that fails).


I've opened an issue in libgit2.

To create a new repository, one should rather rely on git_repository_init() . For more information, you can peek at the header and the tests .

git_repository_open() should rather be used when the repository already exists.

Is there a dedicated forum where I should ask this question?

It's ok to ask programming related question on StackOverflow. Beside this, some libgit2 developers hang out in the #libgit2 channel on irc.freenode.net. However, when you encounter bugs, it's recommended to submit them to the issue tracker .

Update

  • There had been some issues in the past with the way the configuration files are being probbed on Windows. Along with some attempts to fix them. See this issue for some background about this.
  • Beside the complexity of the probbing, some users may want to explictly provide alternate locations for their files. This pull request works this angle.

Considering what you discovered while debugging the libgit2, maybe now would be a good time to open a bug in the issue tracker. Beware that two issues may be at play: the probbing one and and the empty config issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM