libgit2 (2/5)
Repository Initialization

git_repository_init

The git_repository_init [1] function implements repository initialization.

The result of a git_repository_init invocation is similar to that of a git init. We described the result of git init in our Empty Repository tutorial.

Example

The full example is available from our Codeplex repository at Git/libgit2/GitInit1.

File: Git/libgit2/GitInit1/Source/Main.cpp

#include <git2.h>
#include <iostream>

int main(int argc, char* argv[])
{
    // Initialize the library
    int n = git_libgit2_init();
    std::cout << "git_libgit2_init: " << n << std::endl;

    // Initialize a new repository called Libgit2EmptyRepo1.
    // The git_repository_init creates the repository on the filesystem
    // and returns a corresponding git_repository instance
    // to interact with the repository.
    git_repository* repo = 0;
    int err = git_repository_init(&repo, "Libgit2EmptyRepo1", 0);
    if (err == 0)
    {
        std::cout << "Repository initialized successfully" << std::endl;

        git_repository_free(repo);
    }
    else
    {
        std::cout << "Error: git_repository_init failed" << std::endl;
    }

    // git_libgit2_shutdown should be called
    // once for every call to git_libgit2_init
    n = git_libgit2_shutdown();
    std::cout << "git_libgit2_shutdown: " << n << std::endl;

    return 0;
}

References

  1. libgit2 API: git_repository_init

Further Reading

  1. libgit2: Init From the Ground Up

blog comments powered by Disqus

Copyright(c) 2006-2017 Xavier Leclercq | Privacy policy

Home
Contact Us
Search