Example #1
0
int configctl_git_create_config_dir(char *path)
{
	int rc = 0;
	git_repository *repo = NULL;

	git_libgit2_init();

	git_repository_init(&repo, path, 0);
	rc = create_initial_commit(repo);

	git_repository_free(repo);
	git_libgit2_shutdown();

	return rc;
}
Example #2
0
int main(int argc, char * argv[])
{
    bool no_options = true, quiet = false, bare = false, initial_commit = false;
    uint32_t shared = GIT_REPOSITORY_INIT_SHARED_UMASK;
    const char *templ = nullptr, *gitdir = nullptr, *dir = nullptr;

    auto_git_initializer;

    /* Process arguments */

    for (int i = 1; i < argc; ++i)
    {
        auto arg = argv[i];
        StringView a = arg;

        if (arg[0] == '-')
            no_options = false;

        if (arg[0] != '-')
        {
            if (dir)
                usage("extra argument", arg);
            dir = arg;
        }
        else if (a == "-q" || a == "--quiet")
            quiet = true;
        else if (a == "--bare")
            bare = true;
        else if (auto pfxlen = is_prefixed(a, "--template="))
            templ = arg + pfxlen;
        else if (a == "--separate-git-dir")
            gitdir = argv[++i];
        else if (auto pfxlen = is_prefixed(a, "--separate-git-dir="))
            gitdir = arg + pfxlen;
        else if (a == "--shared")
            shared = GIT_REPOSITORY_INIT_SHARED_GROUP;
        else if (auto pfxlen = is_prefixed(a, "--shared="))
            shared = parse_shared(arg + pfxlen);
        else if (a == "--initial-commit")
            initial_commit = true;
        else
            usage("unknown option", arg);
    }

    if (!dir)
        usage("must specify directory to init", nullptr);

    /* Initialize repository */

    Repository repo = no_options
                          ? Repository(dir, Repository::init)
                          : Repository(dir, Repository::init, make_opts(bare, templ, shared, gitdir, dir));

    /* Print a message to stdout like "git init" does */

    if (!quiet)
    {
        printf("Initialized empty Git repository in %s\n",
               (bare || gitdir) ? repo.path() : repo.workdir());
    }

    /* As an extension to the basic "git init" command, this example
	 * gives the option to create an empty initial commit.  This is
	 * mostly to demonstrate what it takes to do that, but also some
	 * people like to have that empty base commit in their repo.
	 */
    if (initial_commit)
    {
        create_initial_commit(repo);
        printf("Created empty initial commit\n");
    }

    return 0;
}