예제 #1
1
/**
 * We still need to fail if part of the namespace is
 * still in use.
 */
void test_refs_branches_create__name_vs_namespace_fail(void)
{
	const char * name;
	struct item {
		const char *first;
		const char *first_alternate;
		const char *second;
	};
	static const struct item item[] = {
		{ "level_one/level_two", "level_one/alternate", "level_one" },
		{ "a/b/c/d/e",           "a/b/c/d/alternate",   "a/b/c/d" },
		{ "ss/tt/uu/vv/ww",      "ss/alternate",        "ss" },
		{ NULL, NULL, NULL },
	};
	const struct item *p;

	retrieve_known_commit(&target, repo);

	for (p=item; p->first; p++) {
		cl_git_pass(git_branch_create(&branch, repo, p->first, target, 0, NULL, NULL));
		cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
		cl_git_pass(git_branch_name(&name, branch));
		cl_assert_equal_s(name, p->first);

		cl_git_pass(git_branch_delete(branch));
		git_reference_free(branch);
		branch = NULL;

		cl_git_pass(git_branch_create(&branch, repo, p->first_alternate, target, 0, NULL, NULL));
		cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
		cl_git_pass(git_branch_name(&name, branch));
		cl_assert_equal_s(name, p->first_alternate);

		/* we do not delete the alternate. */
		git_reference_free(branch);
		branch = NULL;

		cl_git_fail(git_branch_create(&branch, repo, p->second, target, 0, NULL, NULL));
		git_reference_free(branch);
		branch = NULL;
	}
}
예제 #2
0
/**
 * Verify that we can create a branch with a name that matches the
 * namespace of a previously delete branch.
 *
 * git branch level_one/level_two
 * git branch -D level_one/level_two
 * git branch level_one
 *
 * We expect the delete to have deleted the files:
 *     ".git/refs/heads/level_one/level_two"
 *     ".git/logs/refs/heads/level_one/level_two"
 * It may or may not have deleted the (now empty)
 * containing directories.  To match git.git behavior,
 * the second create needs to implicilty delete the
 * directories and create the new files.
 *     "refs/heads/level_one"
 *     "logs/refs/heads/level_one"
 *
 * We should not fail to create the branch or its
 * reflog because of an obsolete namespace container
 * directory.
 */
void test_refs_branches_create__name_vs_namespace(void)
{
	const char * name;
	struct item {
		const char *first;
		const char *second;
	};
	static const struct item item[] = {
		{ "level_one/level_two", "level_one" },
		{ "a/b/c/d/e",           "a/b/c/d" },
		{ "ss/tt/uu/vv/ww",      "ss" },
		/* And one test case that is deeper. */
		{ "xx1/xx2/xx3/xx4",     "xx1/xx2/xx3/xx4/xx5/xx6" },
		{ NULL, NULL },
	};
	const struct item *p;

	retrieve_known_commit(&target, repo);

	for (p=item; p->first; p++) {
		cl_git_pass(git_branch_create(&branch, repo, p->first, target, 0, NULL, NULL));
		cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
		cl_git_pass(git_branch_name(&name, branch));
		cl_assert_equal_s(name, p->first);

		cl_git_pass(git_branch_delete(branch));
		git_reference_free(branch);
		branch = NULL;

		cl_git_pass(git_branch_create(&branch, repo, p->second, target, 0, NULL, NULL));
		git_reference_free(branch);
		branch = NULL;
	}
}
예제 #3
0
파일: create.c 프로젝트: Asquera/libgit2
void test_refs_branches_create__can_not_create_a_branch_pointing_to_a_non_commit_object(void)
{
	/* 53fc32d is the tree of commit e90810b */
	retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016");

	cl_git_fail(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
	git_object_free(target);

	/* 521d87c is an annotated tag pointing to a blob */
	retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91");

	cl_git_fail(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
}
예제 #4
0
파일: create.c 프로젝트: Asquera/libgit2
void test_refs_branches_create__can_create_a_local_branch(void)
{
	retrieve_known_commit(&target, repo);

	cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
	cl_git_pass(git_oid_cmp(&branch_target_oid, git_object_id(target)));
}
예제 #5
0
파일: clone.c 프로젝트: benqian/repobuild
static int create_branch(
	git_reference **branch,
	git_repository *repo,
	const git_oid *target,
	const char *name)
{
	git_commit *head_obj = NULL;
	git_reference *branch_ref = NULL;
	int error;

	/* Find the target commit */
	if ((error = git_commit_lookup(&head_obj, repo, target)) < 0)
		return error;

	/* Create the new branch */
	error = git_branch_create(&branch_ref, repo, name, head_obj, 0);

	git_commit_free(head_obj);

	if (!error)
		*branch = branch_ref;
	else
		git_reference_free(branch_ref);

	return error;
}
예제 #6
0
/*
 *  call-seq:
 *    branches.create(name, target, options = {}) -> branch
 *
 *  Create a new branch with the given +name+, pointing to the +target+.
 *
 *  +name+ needs to be a branch name, not an absolute reference path
 *  (e.g. +development+ instead of +refs/heads/development+).
 *
 *  +target+ needs to be an existing commit in the given repository.
 *
 *  The following options can be passed in the +options+ Hash:
 *
 *  :force ::
 *    Overwrites the branch with the given +name+, if it already exists,
 *    instead of raising an exception.
 *
 *  If a branch with the given +name+ already exists and +:force+ is not +true+,
 *  an exception will be raised.
 *
 *  Returns a Rugged::Branch for the newly created branch.
 */
static VALUE rb_git_branch_collection_create(int argc, VALUE *argv, VALUE self)
{
	VALUE rb_repo = rugged_owner(self), rb_name, rb_target, rb_options;
	git_repository *repo;
	git_reference *branch;
	git_commit *target;
	int error, force = 0;

	rb_scan_args(argc, argv, "20:", &rb_name, &rb_target, &rb_options);

	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);

	Check_Type(rb_name, T_STRING);
	Check_Type(rb_target, T_STRING);

	if (!NIL_P(rb_options)) {
		force = RTEST(rb_hash_aref(rb_options, CSTR2SYM("force")));
	}

	target = (git_commit *)rugged_object_get(repo, rb_target, GIT_OBJ_COMMIT);

	error = git_branch_create(&branch, repo, StringValueCStr(rb_name), target, force);

	git_commit_free(target);

	rugged_exception_check(error);

	return rugged_branch_new(rb_repo, branch);
}
예제 #7
0
void test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
{
	retrieve_known_commit(&target, repo);

	cl_assert_equal_i(GIT_EINVALIDSPEC,
		git_branch_create(&branch, repo, "inv@{id", target, 0, NULL, NULL));
}
예제 #8
0
파일: create.c 프로젝트: Asquera/libgit2
void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
{
	retrieve_known_commit(&target, repo);

	cl_git_pass(git_branch_create(&branch_target_oid, repo, "br2", target, 1));
	cl_git_pass(git_oid_cmp(&branch_target_oid, git_object_id(target)));
}
예제 #9
0
void test_refs_branches_create__default_reflog_message(void)
{
	git_reflog *log;
	const git_reflog_entry *entry;
	git_signature *sig;
	git_config *cfg;

	cl_git_pass(git_repository_config(&cfg, repo));
	cl_git_pass(git_config_set_string(cfg, "user.name", "Foo Bar"));
	cl_git_pass(git_config_set_string(cfg, "user.email", "*****@*****.**"));
	git_config_free(cfg);

	cl_git_pass(git_signature_default(&sig, repo));

	retrieve_known_commit(&target, repo);
	cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, NULL, NULL));
	cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));

	entry = git_reflog_entry_byindex(log, 0);
	cl_assert_equal_s("Branch: created", git_reflog_entry_message(entry));
	cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);

	git_reflog_free(log);
	git_signature_free(sig);
}
예제 #10
0
void test_refs_branches_create__can_create_a_local_branch(void)
{
	retrieve_known_commit(&target, repo);

	cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0, NULL, NULL));
	cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
}
예제 #11
0
void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
{
	retrieve_known_commit(&target, repo);

	cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1, NULL, NULL));
	cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
	cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
}
예제 #12
0
파일: create.c 프로젝트: Asquera/libgit2
void test_refs_branches_create__creating_a_branch_targeting_a_tag_dereferences_it_to_its_commit(void)
{
	/* b25fa35 is a tag, pointing to another tag which points to a commit */
	retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");

	cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));
	cl_git_pass(git_oid_streq(&branch_target_oid, "e90810b8df3e80c413d903f631643c716887138d"));
}
예제 #13
0
파일: tree.c 프로젝트: Kat7984/libgit2
void assert_conflict(
	const char *entry_path,
	const char *new_content,
	const char *parent_sha,
	const char *commit_sha)
{
	git_index *index;
	git_object *hack_tree;
	git_reference *branch, *head;
	git_buf file_path = GIT_BUF_INIT;

	cl_git_pass(git_repository_index(&index, g_repo));

	/* Create a branch pointing at the parent */
	cl_git_pass(git_revparse_single(&g_object, g_repo, parent_sha));
	cl_git_pass(git_branch_create(&branch, g_repo,
		"potential_conflict", (git_commit *)g_object, 0));

	/* Make HEAD point to this branch */
	cl_git_pass(git_reference_symbolic_create(
		&head, g_repo, "HEAD", git_reference_name(branch), 1, NULL));
	git_reference_free(head);
	git_reference_free(branch);

	/* Checkout the parent */
	g_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
	cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));

	/* Hack-ishy workaound to ensure *all* the index entries
	 * match the content of the tree
	 */
	cl_git_pass(git_object_peel(&hack_tree, g_object, GIT_OBJ_TREE));
	cl_git_pass(git_index_read_tree(index, (git_tree *)hack_tree));
	git_object_free(hack_tree);
	git_object_free(g_object);
	g_object = NULL;

	/* Create a conflicting file */
	cl_git_pass(git_buf_joinpath(&file_path, "./testrepo", entry_path));
	cl_git_mkfile(git_buf_cstr(&file_path), new_content);
	git_buf_free(&file_path);

	/* Trying to checkout the original commit */
	cl_git_pass(git_revparse_single(&g_object, g_repo, commit_sha));

	g_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
	cl_assert_equal_i(
		GIT_ECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts));

	/* Stage the conflicting change */
	cl_git_pass(git_index_add_bypath(index, entry_path));
	cl_git_pass(git_index_write(index));
	git_index_free(index);

	cl_assert_equal_i(
		GIT_ECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts));
}
예제 #14
0
static void assert_merge_and_or_remote_key_missing(git_repository *repository, const git_commit *target, const char *entry_name)
{
	git_reference *branch;

	cl_assert_equal_i(GIT_OBJ_COMMIT, git_object_type((git_object*)target));
	cl_git_pass(git_branch_create(&branch, repository, entry_name, (git_commit*)target, 0));

	cl_assert_equal_i(GIT_ENOTFOUND, git_branch_tracking(&tracking, branch));

	git_reference_free(branch);
}
예제 #15
0
파일: create.c 프로젝트: Asquera/libgit2
void test_refs_branches_create__can_not_create_a_branch_pointing_at_an_object_unknown_from_the_repository(void)
{
	git_repository *repo2;

	/* Open another instance of the same repository */
	cl_git_pass(git_repository_open(&repo2, cl_fixture("testrepo.git")));

	/* Retrieve a commit object from this different repository */
	retrieve_known_commit(&target, repo2);

	cl_git_fail(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));

	git_repository_free(repo2);
}
예제 #16
0
파일: create.c 프로젝트: Asquera/libgit2
void test_refs_branches_create__creating_a_local_branch_triggers_the_creation_of_a_new_direct_reference(void)
{
	git_reference *branch;

	retrieve_known_commit(&target, repo);

	cl_git_fail(git_reference_lookup(&branch, repo, GIT_REFS_HEADS_DIR NEW_BRANCH_NAME));

	cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0));

	cl_git_pass(git_reference_lookup(&branch, repo, GIT_REFS_HEADS_DIR NEW_BRANCH_NAME));
	cl_assert(git_reference_type(branch) == GIT_REF_OID);

	git_reference_free(branch);
}
예제 #17
0
PyObject *
Repository_create_branch(Repository *self, PyObject *args)
{
    Commit *py_commit;
    git_reference *c_reference;
    char *c_name;
    int err, force = 0;

    if (!PyArg_ParseTuple(args, "sO!|i", &c_name, &CommitType, &py_commit, &force))
        return NULL;

    err = git_branch_create(&c_reference, self->repo, c_name, py_commit->commit, force, NULL, NULL);
    if (err < 0)
        return Error_set(err);

    return wrap_branch(c_reference, self);
}
예제 #18
0
void test_refs_branches_create__cannot_force_create_over_current_branch(void)
{
	const git_oid *oid;
	git_reference *branch2;
	retrieve_known_commit(&target, repo);

	cl_git_pass(git_branch_lookup(&branch2, repo, "master", GIT_BRANCH_LOCAL));
	cl_assert_equal_s("refs/heads/master", git_reference_name(branch2));
	cl_assert_equal_i(true, git_branch_is_head(branch2));
	oid = git_reference_target(branch2);

	cl_git_fail_with(-1, git_branch_create(&branch, repo, "master", target, 1, NULL, NULL));
	branch = NULL;
	cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
	cl_assert_equal_s("refs/heads/master", git_reference_name(branch));
	cl_git_pass(git_oid_cmp(git_reference_target(branch), oid));
	git_reference_free(branch2);
}
예제 #19
0
파일: create.c 프로젝트: 1336/libgit2
void test_refs_branches_create__default_reflog_message(void)
{
	git_reflog *log;
	git_buf buf = GIT_BUF_INIT;
	const git_reflog_entry *entry;
	git_annotated_commit *annotated;
	git_signature *sig;
	git_config *cfg;

	cl_git_pass(git_repository_config(&cfg, repo));
	cl_git_pass(git_config_set_string(cfg, "user.name", "Foo Bar"));
	cl_git_pass(git_config_set_string(cfg, "user.email", "*****@*****.**"));
	git_config_free(cfg);

	cl_git_pass(git_signature_default(&sig, repo));

	retrieve_known_commit(&target, repo);
	cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false));
	cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));

	entry = git_reflog_entry_byindex(log, 0);
	cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
	cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry));
	cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);

	cl_git_pass(git_reference_remove(repo, "refs/heads/" NEW_BRANCH_NAME));
	git_reference_free(branch);
	git_reflog_free(log);
	git_buf_clear(&buf);

	cl_git_pass(git_annotated_commit_from_revspec(&annotated, repo, "e90810b8df3"));
	cl_git_pass(git_branch_create_from_annotated(&branch, repo, NEW_BRANCH_NAME, annotated, true));
	cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));

	entry = git_reflog_entry_byindex(log, 0);
	cl_git_pass(git_buf_printf(&buf, "branch: Created from e90810b8df3"));
	cl_assert_equal_s(git_buf_cstr(&buf), git_reflog_entry_message(entry));
	cl_assert_equal_s(sig->email, git_reflog_entry_committer(entry)->email);

	git_annotated_commit_free(annotated);
	git_buf_free(&buf);
	git_reflog_free(log);
	git_signature_free(sig);
}
예제 #20
0
void test_refs_branches_create__creation_creates_new_reflog(void)
{
	git_reflog *log;
	const git_reflog_entry *entry;
	git_signature *sig;

	cl_git_pass(git_signature_now(&sig, "me", "*****@*****.**"));

	retrieve_known_commit(&target, repo);
	cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, sig, "create!"));
	cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));

	cl_assert_equal_i(1, git_reflog_entrycount(log));
	entry = git_reflog_entry_byindex(log, 0);
	cl_assert_equal_s("create!", git_reflog_entry_message(entry));
	cl_assert_equal_s("*****@*****.**", git_reflog_entry_committer(entry)->email);

	git_reflog_free(log);
	git_signature_free(sig);
}
예제 #21
0
void test_refs_branches_create__can_create_branch_with_unicode(void)
{
	const char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D";
	const char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D";
	const char *emoji = "\xF0\x9F\x8D\xB7";
	const char *names[] = { nfc, nfd, emoji };
	const char *alt[] = { nfd, nfc, NULL };
	const char *expected[] = { nfc, nfd, emoji };
	unsigned int i;
	bool fs_decompose_unicode =
		git_path_does_fs_decompose_unicode(git_repository_path(repo));

	retrieve_known_commit(&target, repo);

	if (cl_repo_get_bool(repo, "core.precomposeunicode"))
		expected[1] = nfc;
	/* test decomp. because not all Mac filesystems decompose unicode */
	else if (fs_decompose_unicode)
		expected[0] = nfd;

	for (i = 0; i < ARRAY_SIZE(names); ++i) {
		const char *name;
		cl_git_pass(git_branch_create(
			&branch, repo, names[i], target, 0, NULL, NULL));
		cl_git_pass(git_oid_cmp(
			git_reference_target(branch), git_commit_id(target)));

		cl_git_pass(git_branch_name(&name, branch));
		cl_assert_equal_s(expected[i], name);
		assert_branch_matches_name(expected[i], names[i]);
		if (fs_decompose_unicode && alt[i])
			assert_branch_matches_name(expected[i], alt[i]);

		cl_git_pass(git_branch_delete(branch));
		git_reference_free(branch);
		branch = NULL;
	}
}
예제 #22
0
void test_refs_reflog_messages__creating_branches_default_messages(void)
{
	git_buf buf = GIT_BUF_INIT;
	git_annotated_commit *annotated;
	git_object *obj;
	git_commit *target;
	git_reference *branch1, *branch2;

	cl_git_pass(git_revparse_single(&obj, g_repo, "e90810b8df3"));
	cl_git_pass(git_commit_lookup(&target, g_repo, git_object_id(obj)));
	git_object_free(obj);

	cl_git_pass(git_branch_create(&branch1, g_repo, NEW_BRANCH_NAME, target, false));

	cl_git_pass(git_buf_printf(&buf, "branch: Created from %s", git_oid_tostr_s(git_commit_id(target))));
	cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
		GIT_OID_HEX_ZERO,
		git_oid_tostr_s(git_commit_id(target)),
		g_email, git_buf_cstr(&buf));

	cl_git_pass(git_reference_remove(g_repo, "refs/heads/" NEW_BRANCH_NAME));

	cl_git_pass(git_annotated_commit_from_revspec(&annotated, g_repo, "e90810b8df3"));
	cl_git_pass(git_branch_create_from_annotated(&branch2, g_repo, NEW_BRANCH_NAME, annotated, true));

	cl_reflog_check_entry(g_repo, "refs/heads/" NEW_BRANCH_NAME, 0,
		GIT_OID_HEX_ZERO,
		git_oid_tostr_s(git_commit_id(target)),
		g_email, "branch: Created from e90810b8df3");

	git_annotated_commit_free(annotated);
	git_buf_free(&buf);
	git_commit_free(target);
	git_reference_free(branch1);
	git_reference_free(branch2);
}
예제 #23
0
void GitRepository::branch(const QString& name)
{
    git_repository* repo = repository();
    git_auto<git_reference> branch;

    int err = git_branch_lookup(&branch, repo, name.toLatin1(), GIT_BRANCH_LOCAL);
    if (err == GIT_ENOTFOUND){
        git_oid parent_id;
        git_auto<git_commit> parent;

        git_eval(git_reference_name_to_id(&parent_id, repo, "HEAD"));
        git_eval(git_commit_lookup(&parent, repo, &parent_id));
        git_eval(git_branch_create(&branch, repo, name.toLocal8Bit(), parent, 1));
    }else{
        git_eval(err);
    }

    git_eval(git_repository_set_head(repo, git_reference_name(branch)));

    git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
    opts.checkout_strategy = GIT_CHECKOUT_FORCE;

    git_eval(git_checkout_head(repo, &opts));
}
예제 #24
0
파일: create.c 프로젝트: Asquera/libgit2
void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with_an_existing_one(void)
{
	retrieve_known_commit(&target, repo);

	cl_git_fail(git_branch_create(&branch_target_oid, repo, "br2", target, 0));
}
예제 #25
0
void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with_an_existing_one(void)
{
	retrieve_known_commit(&target, repo);

	cl_assert_equal_i(GIT_EEXISTS, git_branch_create(&branch, repo, "br2", target, 0, NULL, NULL));
}
예제 #26
0
파일: main.c 프로젝트: cemeyer/git-isvn
static void
checkout(git_repository *repo)
{
	git_reference *master_ref, *remote_ref, *HEAD_ref, *tmpr;
	git_checkout_options co_opts;
	const char *remote_br_name;
	git_commit *remote_commit;
	git_object *remote_obj;
	char *remotebr;
	int rc;

	remotebr = NULL;
	xasprintf(&remotebr, "refs/remotes/%s/%s", option_origin,
	    option_trunk);

	rc = git_reference_lookup(&remote_ref, repo, remotebr);
	if (rc)
		die("git_reference_lookup(%s): %d", remotebr, rc);

	rc = git_branch_name(&remote_br_name, remote_ref);
	if (rc)
		die("git_branch_name: %d", rc);

	rc = git_reference_peel(&remote_obj, remote_ref, GIT_OBJ_COMMIT);
	if (rc)
		die("git_reference_peel");

	rc = git_commit_lookup(&remote_commit, repo,
	    git_object_id(remote_obj));
	if (rc)
		die("git_commit_lookup");

	rc = git_branch_create(&master_ref, repo, "master", remote_commit,
	    false, NULL, NULL);
	if (rc)
		die("git_branch_create: %d", rc);

	rc = git_reference_symbolic_create(&HEAD_ref, repo, "HEAD",
	    "refs/heads/master", false, NULL, NULL);
	if (rc && rc != GIT_EEXISTS)
		die("git_reference_symbolic_create: %d", rc);

	rc = git_branch_set_upstream(master_ref, remote_br_name);
	if (rc)
		/* TODO: '' is not a valid remote name */
#if 0
		die("git_branch_set_upstream: %d (%d/%s)", rc,
		    giterr_last()->klass, giterr_last()->message);
#else
		printf("XXXgit_branch_set_upstream: %d (%d/%s)\n", rc,
		    giterr_last()->klass, giterr_last()->message);
#endif

	rc = git_reference_lookup(&tmpr, repo, "refs/heads/master");
	if (rc)
		die("%s: reference_lookup: master doesn't exist?", __func__);
	if (git_reference_cmp(tmpr, master_ref) != 0)
		die("mismatched master");

	co_opts = (git_checkout_options) GIT_CHECKOUT_OPTIONS_INIT;
	co_opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE;
	rc = git_checkout_head(repo, &co_opts);
	if (rc)
		die("git_checkout_head");

	free(remotebr);
	git_commit_free(remote_commit);
	git_object_free(remote_obj);
	git_reference_free(tmpr);
	git_reference_free(HEAD_ref);
	git_reference_free(master_ref);
	git_reference_free(remote_ref);
}