Commit 4e498646 by Carlos Martín Nieto

repository: remove log message override for switching the active branch

We want to use the "checkout: moving from ..." message in order to let
git know when a change of branch has happened. Make the convenience
functions for this goal write this message.
parent 412a3808
......@@ -603,13 +603,11 @@ GIT_EXTERN(int) git_repository_hashfile(
*
* @param repo Repository pointer
* @param refname Canonical name of the reference the HEAD should point at
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_repository_set_head(
git_repository* repo,
const char* refname,
const char *log_message);
const char* refname);
/**
* Make the repository HEAD directly point to the Commit.
......@@ -625,13 +623,11 @@ GIT_EXTERN(int) git_repository_set_head(
*
* @param repo Repository pointer
* @param commitish Object id of the Commit the HEAD should point to
* @param log_message The one line long message to be appended to the reflog
* @return 0 on success, or an error code
*/
GIT_EXTERN(int) git_repository_set_head_detached(
git_repository* repo,
const git_oid* commitish,
const char *log_message);
const git_oid* commitish);
/**
* Detach the HEAD.
......@@ -647,13 +643,11 @@ GIT_EXTERN(int) git_repository_set_head_detached(
* Otherwise, the HEAD will be detached and point to the peeled Commit.
*
* @param repo Repository pointer
* @param reflog_message The one line long message to be appended to the reflog
* @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing
* branch or an error code
*/
GIT_EXTERN(int) git_repository_detach_head(
git_repository* repo,
const char *reflog_message);
git_repository* repo);
/**
* Repository state
......
......@@ -127,8 +127,7 @@ static int update_head_to_new_branch(
if (!error)
error = git_repository_set_head(
repo, git_reference_name(tracking_branch),
reflog_message);
repo, git_reference_name(tracking_branch));
git_reference_free(tracking_branch);
......@@ -169,7 +168,7 @@ static int update_head_to_remote(
error = git_remote_default_branch(&branch, remote);
if (error == GIT_ENOTFOUND) {
error = git_repository_set_head_detached(
repo, remote_head_id, reflog_message);
repo, remote_head_id);
goto cleanup;
}
......
......@@ -589,7 +589,7 @@ static int reference__rename(git_reference **out, git_reference *ref, const char
/* Update HEAD it was pointing to the reference being renamed */
if (should_head_be_updated &&
(error = git_repository_set_head(ref->db->repo, normalized, message)) < 0) {
(error = git_repository_set_head(ref->db->repo, normalized)) < 0) {
giterr_set(GITERR_REFERENCE, "Failed to update HEAD after renaming reference");
return error;
}
......@@ -1284,10 +1284,8 @@ int git_reference_is_valid_name(const char *refname)
return git_reference__is_valid_name(refname, GIT_REF_FORMAT_ALLOW_ONELEVEL);
}
const char *git_reference_shorthand(const git_reference *ref)
const char *git_reference__shorthand(const char *name)
{
const char *name = ref->name;
if (!git__prefixcmp(name, GIT_REFS_HEADS_DIR))
return name + strlen(GIT_REFS_HEADS_DIR);
else if (!git__prefixcmp(name, GIT_REFS_TAGS_DIR))
......@@ -1300,3 +1298,8 @@ const char *git_reference_shorthand(const git_reference *ref)
/* No shorthands are avaiable, so just return the name */
return name;
}
const char *git_reference_shorthand(const git_reference *ref)
{
return git_reference__shorthand(ref->name);
}
......@@ -74,6 +74,7 @@ int git_reference__is_valid_name(const char *refname, unsigned int flags);
int git_reference__is_branch(const char *ref_name);
int git_reference__is_remote(const char *ref_name);
int git_reference__is_tag(const char *ref_name);
const char *git_reference__shorthand(const char *name);
/**
* Lookup a reference by name and try to resolve to an OID.
......
......@@ -1889,39 +1889,62 @@ cleanup:
return error;
}
static bool looks_like_a_branch(const char *refname)
static int checkout_message(git_buf *out, git_reference *old, const char *new)
{
return git__prefixcmp(refname, GIT_REFS_HEADS_DIR) == 0;
git_buf_puts(out, "checkout: moving from ");
if (git_reference_type(old) == GIT_REF_SYMBOLIC)
git_buf_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
else
git_buf_puts(out, git_oid_tostr_s(git_reference_target(old)));
git_buf_puts(out, " to ");
if (git_reference__is_branch(new))
git_buf_puts(out, git_reference__shorthand(new));
else
git_buf_puts(out, new);
if (git_buf_oom(out))
return -1;
return 0;
}
int git_repository_set_head(
git_repository* repo,
const char* refname,
const char *log_message)
const char* refname)
{
git_reference *ref,
*new_head = NULL;
git_reference *ref = NULL, *current = NULL, *new_head = NULL;
git_buf log_message = GIT_BUF_INIT;
int error;
assert(repo && refname);
if ((error = git_reference_lookup(&current, repo, GIT_HEAD_FILE)) < 0)
return error;
if ((error = checkout_message(&log_message, current, refname)) < 0)
goto cleanup;
error = git_reference_lookup(&ref, repo, refname);
if (error < 0 && error != GIT_ENOTFOUND)
return error;
goto cleanup;
if (!error) {
if (git_reference_is_branch(ref)) {
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
git_reference_name(ref), true, log_message);
git_reference_name(ref), true, git_buf_cstr(&log_message));
} else {
error = git_repository_set_head_detached(repo, git_reference_target(ref),
log_message);
error = git_repository_set_head_detached(repo, git_reference_target(ref));
}
} else if (looks_like_a_branch(refname)) {
} else if (git_reference__is_branch(refname)) {
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
true, log_message);
true, git_buf_cstr(&log_message));
}
cleanup:
git_reference_free(current);
git_reference_free(ref);
git_reference_free(new_head);
return error;
......@@ -1929,55 +1952,66 @@ int git_repository_set_head(
int git_repository_set_head_detached(
git_repository* repo,
const git_oid* commitish,
const char *log_message)
const git_oid* commitish)
{
int error;
git_object *object,
*peeled = NULL;
git_reference *new_head = NULL;
git_buf log_message = GIT_BUF_INIT;
git_object *object = NULL, *peeled = NULL;
git_reference *new_head = NULL, *current = NULL;
assert(repo && commitish);
if ((error = git_object_lookup(&object, repo, commitish, GIT_OBJ_ANY)) < 0)
if ((error = git_reference_lookup(&current, repo, GIT_HEAD_FILE)) < 0)
return error;
if ((error = git_object_lookup(&object, repo, commitish, GIT_OBJ_ANY)) < 0)
goto cleanup;
if ((error = git_object_peel(&peeled, object, GIT_OBJ_COMMIT)) < 0)
goto cleanup;
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, log_message);
if ((error = checkout_message(&log_message, current, git_oid_tostr_s(git_object_id(peeled)))) < 0)
goto cleanup;
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_buf_cstr(&log_message));
cleanup:
git_object_free(object);
git_object_free(peeled);
git_reference_free(current);
git_reference_free(new_head);
return error;
}
int git_repository_detach_head(
git_repository* repo,
const char *reflog_message)
int git_repository_detach_head(git_repository* repo)
{
git_reference *old_head = NULL,
*new_head = NULL;
git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
git_object *object = NULL;
git_buf log_message = GIT_BUF_INIT;
int error;
assert(repo);
if ((error = git_repository_head(&old_head, repo)) < 0)
if ((error = git_reference_lookup(&current, repo, GIT_HEAD_FILE)) < 0)
return error;
if ((error = git_repository_head(&old_head, repo)) < 0)
goto cleanup;
if ((error = git_object_lookup(&object, repo, git_reference_target(old_head), GIT_OBJ_COMMIT)) < 0)
goto cleanup;
if ((error = checkout_message(&log_message, current, git_oid_tostr_s(git_object_id(object)))) < 0)
goto cleanup;
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
1, reflog_message);
1, git_buf_cstr(&log_message));
cleanup:
git_object_free(object);
git_reference_free(old_head);
git_reference_free(new_head);
git_reference_free(current);
return error;
}
......
......@@ -984,7 +984,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
update_options.checkout_opts.checkout_strategy = update_options.clone_checkout_strategy;
if ((error = git_clone(&sub_repo, submodule_url, sm->path, &clone_options)) < 0 ||
(error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm), NULL)) < 0 ||
(error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm))) < 0 ||
(error = git_checkout_head(sub_repo, &update_options.checkout_opts)) != 0)
goto done;
} else {
......@@ -996,7 +996,7 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
if ((error = git_submodule_open(&sub_repo, sm)) < 0 ||
(error = git_object_lookup(&target_commit, sub_repo, git_submodule_index_id(sm), GIT_OBJ_COMMIT)) < 0 ||
(error = git_checkout_tree(sub_repo, target_commit, &update_options.checkout_opts)) != 0 ||
(error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm), NULL)) < 0)
(error = git_repository_set_head_detached(sub_repo, git_submodule_index_id(sm))) < 0)
goto done;
/* Invalidate the wd flags as the workdir has been updated. */
......
......@@ -113,7 +113,7 @@ void test_checkout_crlf__detect_crlf_autocrlf_true_utf8(void)
cl_repo_set_bool(g_repo, "core.autocrlf", true);
git_repository_set_head(g_repo, "refs/heads/utf8", NULL);
git_repository_set_head(g_repo, "refs/heads/utf8");
git_checkout_head(g_repo, &opts);
if (GIT_EOL_NATIVE == GIT_EOL_LF)
......
......@@ -63,7 +63,7 @@ void test_checkout_tree__can_checkout_and_remove_directory(void)
cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
cl_assert_equal_i(true, git_path_isdir("./testrepo/ab/"));
cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
......@@ -78,7 +78,7 @@ void test_checkout_tree__can_checkout_and_remove_directory(void)
cl_git_pass(git_revparse_single(&g_object, g_repo, "master"));
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
/* This directory should no longer exist */
cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
......@@ -163,7 +163,7 @@ void test_checkout_tree__can_switch_branches(void)
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
cl_assert(git_path_isfile("testrepo/README"));
cl_assert(git_path_isfile("testrepo/branch_file.txt"));
......@@ -183,7 +183,7 @@ void test_checkout_tree__can_switch_branches(void)
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
cl_assert(git_path_isfile("testrepo/README"));
cl_assert(git_path_isfile("testrepo/branch_file.txt"));
......@@ -253,7 +253,7 @@ static int checkout_tree_with_blob_ignored_in_workdir(int strategy, bool isdir)
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
cl_assert(git_path_isfile("testrepo/README"));
cl_assert(git_path_isfile("testrepo/branch_file.txt"));
......@@ -313,7 +313,7 @@ void test_checkout_tree__can_overwrite_ignored_by_default(void)
{
cl_git_pass(checkout_tree_with_blob_ignored_in_workdir(GIT_CHECKOUT_SAFE, false));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
cl_assert(git_path_isfile("testrepo/ab/4.txt"));
......@@ -334,7 +334,7 @@ void test_checkout_tree__can_overwrite_ignored_folder_by_default(void)
{
cl_git_pass(checkout_tree_with_blob_ignored_in_workdir(GIT_CHECKOUT_SAFE, true));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
cl_assert(git_path_isfile("testrepo/ab/4.txt"));
......@@ -367,7 +367,7 @@ void test_checkout_tree__can_update_only(void)
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
assert_on_branch(g_repo, "dir");
......@@ -396,7 +396,7 @@ void test_checkout_tree__can_checkout_with_pattern(void)
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_git_pass(
git_repository_set_head_detached(g_repo, git_object_id(g_object), NULL));
git_repository_set_head_detached(g_repo, git_object_id(g_object)));
git_object_free(g_object);
g_object = NULL;
......@@ -435,7 +435,7 @@ void test_checkout_tree__can_disable_pattern_match(void)
cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_git_pass(
git_repository_set_head_detached(g_repo, git_object_id(g_object), NULL));
git_repository_set_head_detached(g_repo, git_object_id(g_object)));
git_object_free(g_object);
g_object = NULL;
......@@ -677,7 +677,7 @@ void test_checkout_tree__can_checkout_with_last_workdir_item_missing(void)
cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id));
cl_git_pass(git_checkout_tree(g_repo, (git_object *)commit, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
cl_git_pass(p_mkdir("./testrepo/this-is-dir", 0777));
cl_git_mkfile("./testrepo/this-is-dir/contained_file", "content\n");
......@@ -1049,7 +1049,7 @@ void test_checkout_tree__case_changing_rename(void)
cl_git_pass(git_commit_lookup(&dir_commit, g_repo, &dir_commit_id));
cl_git_pass(git_checkout_tree(g_repo, (git_object *)dir_commit, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir"));
cl_assert(git_path_isfile("testrepo/README"));
case_sensitive = !git_path_isfile("testrepo/readme");
......@@ -1086,7 +1086,7 @@ void test_checkout_tree__case_changing_rename(void)
cl_git_pass(git_commit_lookup(&master_commit, g_repo, &master_id));
cl_git_pass(git_checkout_tree(g_repo, (git_object *)master_commit, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master", NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/master"));
assert_on_branch(g_repo, "master");
......@@ -1285,7 +1285,7 @@ void test_checkout_tree__safe_proceeds_if_no_index(void)
cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY));
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees", NULL, NULL));
cl_git_pass(git_repository_set_head(g_repo, "refs/heads/subtrees"));
cl_assert(git_path_isfile("testrepo/README"));
cl_assert(git_path_isfile("testrepo/branch_file.txt"));
......
......@@ -122,7 +122,7 @@ void test_checkout_typechange__checkout_typechanges_safe(void)
cl_git_pass(git_checkout_tree(g_repo, obj, &opts));
cl_git_pass(
git_repository_set_head_detached(g_repo, git_object_id(obj), NULL));
git_repository_set_head_detached(g_repo, git_object_id(obj)));
assert_workdir_matches_tree(g_repo, git_object_id(obj), NULL, true);
......@@ -231,7 +231,7 @@ void test_checkout_typechange__checkout_with_conflicts(void)
cl_assert(!git_path_exists("typechanges/untracked"));
cl_git_pass(
git_repository_set_head_detached(g_repo, git_object_id(obj), NULL));
git_repository_set_head_detached(g_repo, git_object_id(obj)));
assert_workdir_matches_tree(g_repo, git_object_id(obj), NULL, true);
......
......@@ -230,7 +230,7 @@ void test_clone_nonetwork__can_detached_head(void)
cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options));
cl_git_pass(git_revparse_single(&obj, g_repo, "master~1"));
cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(obj), NULL));
cl_git_pass(git_repository_set_head_detached(g_repo, git_object_id(obj)));
cl_git_pass(git_clone(&cloned, "./foo", "./foo1", &g_options));
......
......@@ -39,13 +39,13 @@ void test_network_remote_defaultbranch__master(void)
void test_network_remote_defaultbranch__master_does_not_win(void)
{
cl_git_pass(git_repository_set_head(g_repo_a, "refs/heads/not-good", NULL));
cl_git_pass(git_repository_set_head(g_repo_a, "refs/heads/not-good"));
assert_default_branch("refs/heads/not-good");
}
void test_network_remote_defaultbranch__master_on_detached(void)
{
cl_git_pass(git_repository_detach_head(g_repo_a, NULL));
cl_git_pass(git_repository_detach_head(g_repo_a));
assert_default_branch("refs/heads/master");
}
......@@ -74,7 +74,7 @@ void test_network_remote_defaultbranch__detached_sharing_nonbranch_id(void)
git_repository *cloned_repo;
cl_git_pass(git_reference_name_to_id(&id, g_repo_a, "HEAD"));
cl_git_pass(git_repository_detach_head(g_repo_a, NULL));
cl_git_pass(git_repository_detach_head(g_repo_a));
cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/master"));
cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/not-good"));
cl_git_pass(git_reference_create(&ref, g_repo_a, "refs/foo/bar", &id, 1, NULL));
......
......@@ -43,8 +43,7 @@ void perf__do_merge(const char *fixture,
cl_git_pass(git_checkout_tree(g_repo, (git_object*)commit_a, &checkout_opts));
perf__timer__stop(&t_checkout);
cl_git_pass(git_repository_set_head(g_repo,
git_reference_name(ref_branch_a), NULL));
cl_git_pass(git_repository_set_head(g_repo, git_reference_name(ref_branch_a)));
git_oid_fromstr(&oid_b, id_b);
cl_git_pass(git_commit_lookup(&commit_b, g_repo, &oid_b));
......
......@@ -308,7 +308,7 @@ void test_rebase_setup__merge_null_branch_uses_HEAD(void)
cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo));
cl_git_pass(git_repository_set_head(repo, "refs/heads/beef", NULL));
cl_git_pass(git_repository_set_head(repo, "refs/heads/beef"));
cl_git_pass(git_checkout_head(repo, &checkout_opts));
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
......
......@@ -75,7 +75,7 @@ void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(
git_reference_free(head);
/* Detach HEAD and make it target the commit that "master" points to */
git_repository_detach_head(repo, NULL);
git_repository_detach_head(repo);
cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
cl_git_pass(git_branch_delete(branch));
......
......@@ -38,8 +38,8 @@ void test_repo_head__head_detached(void)
cl_assert_equal_i(false, git_repository_head_detached(repo));
cl_git_pass(git_repository_detach_head(repo, "CABLE DETACHED"));
check_last_reflog_entry(g_email, "CABLE DETACHED");
cl_git_pass(git_repository_detach_head(repo));
check_last_reflog_entry(g_email, "checkout: moving from master to a65fedf39aefe402d3bb6e24df4d4f5fe4547750");
cl_assert_equal_i(true, git_repository_head_detached(repo));
/* take the repo back to it's original state */
......@@ -73,7 +73,7 @@ void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_
{
git_reference *head;
cl_git_pass(git_repository_set_head(repo, "refs/heads/doesnt/exist/yet", NULL));
cl_git_pass(git_repository_set_head(repo, "refs/heads/doesnt/exist/yet"));
cl_assert_equal_i(false, git_repository_head_detached(repo));
......@@ -82,19 +82,19 @@ void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_
void test_repo_head__set_head_Returns_ENOTFOUND_when_the_reference_doesnt_exist(void)
{
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head(repo, "refs/tags/doesnt/exist/yet", NULL));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head(repo, "refs/tags/doesnt/exist/yet"));
}
void test_repo_head__set_head_Fails_when_the_reference_points_to_a_non_commitish(void)
{
cl_git_fail(git_repository_set_head(repo, "refs/tags/point_to_blob", NULL));
cl_git_fail(git_repository_set_head(repo, "refs/tags/point_to_blob"));
}
void test_repo_head__set_head_Attaches_HEAD_when_the_reference_points_to_a_branch(void)
{
git_reference *head;
cl_git_pass(git_repository_set_head(repo, "refs/heads/br2", NULL));
cl_git_pass(git_repository_set_head(repo, "refs/heads/br2"));
cl_assert_equal_i(false, git_repository_head_detached(repo));
......@@ -121,7 +121,7 @@ static void assert_head_is_correctly_detached(void)
void test_repo_head__set_head_Detaches_HEAD_when_the_reference_doesnt_point_to_a_branch(void)
{
cl_git_pass(git_repository_set_head(repo, "refs/tags/test", NULL));
cl_git_pass(git_repository_set_head(repo, "refs/tags/test"));
cl_assert_equal_i(true, git_repository_head_detached(repo));
......@@ -134,7 +134,7 @@ void test_repo_head__set_head_detached_Return_ENOTFOUND_when_the_object_doesnt_e
cl_git_pass(git_oid_fromstr(&oid, "deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head_detached(repo, &oid, NULL));
cl_assert_equal_i(GIT_ENOTFOUND, git_repository_set_head_detached(repo, &oid));
}
void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(void)
......@@ -143,7 +143,7 @@ void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(vo
cl_git_pass(git_revparse_single(&blob, repo, "point_to_blob"));
cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob), NULL));
cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob)));
git_object_free(blob);
}
......@@ -155,7 +155,7 @@ void test_repo_head__set_head_detached_Detaches_HEAD_and_make_it_point_to_the_pe
cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
cl_assert_equal_i(GIT_OBJ_TAG, git_object_type(tag));
cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag), NULL));
cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
assert_head_is_correctly_detached();
......@@ -166,7 +166,7 @@ void test_repo_head__detach_head_Detaches_HEAD_and_make_it_point_to_the_peeled_c
{
cl_assert_equal_i(false, git_repository_head_detached(repo));
cl_git_pass(git_repository_detach_head(repo, NULL));
cl_git_pass(git_repository_detach_head(repo));
assert_head_is_correctly_detached();
}
......@@ -177,7 +177,7 @@ void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void
cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/tags/point_to_blob", 1, NULL));
cl_git_fail(git_repository_detach_head(repo, NULL));
cl_git_fail(git_repository_detach_head(repo));
git_reference_free(head);
}
......@@ -186,7 +186,7 @@ void test_repo_head__detaching_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
{
make_head_unborn(repo, NON_EXISTING_HEAD);
cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_detach_head(repo, NULL));
cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_detach_head(repo));
}
void test_repo_head__retrieving_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void)
......@@ -254,15 +254,15 @@ void test_repo_head__setting_head_updates_reflog(void)
cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", "message1"));
cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn", "message2"));
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
cl_git_pass(git_repository_set_head(repo, "refs/heads/unborn"));
cl_git_pass(git_revparse_single(&tag, repo, "tags/test"));
cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag),"message3"));
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", "message4"));
cl_git_pass(git_repository_set_head_detached(repo, git_object_id(tag)));
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
test_reflog(repo, 2, NULL, "refs/heads/haacked", "foo@example.com", "message1");
test_reflog(repo, 1, NULL, "tags/test^{commit}", "foo@example.com", "message3");
test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "foo@example.com", "message4");
test_reflog(repo, 2, NULL, "refs/heads/haacked", "foo@example.com", "checkout: moving from master to haacked");
test_reflog(repo, 1, NULL, "tags/test^{commit}", "foo@example.com", "checkout: moving from unborn to e90810b8df3e80c413d903f631643c716887138d");
test_reflog(repo, 0, "tags/test^{commit}", "refs/heads/haacked", "foo@example.com", "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked");
git_object_free(tag);
git_signature_free(sig);
......@@ -297,14 +297,14 @@ void test_repo_head__detaching_writes_reflog(void)
cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
msg = "message1";
msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
cl_git_pass(git_repository_set_head_detached(repo, &id, msg));
cl_git_pass(git_repository_set_head_detached(repo, &id));
assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d", msg);
msg = "message2";
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", msg));
msg = "checkout: moving from e90810b8df3e80c413d903f631643c716887138d to haacked";
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
assert_head_reflog(repo, 0, "e90810b8df3e80c413d903f631643c716887138d",
"258f0e2a959a364e40ed6603d5d44fbb24765b10", msg);
......@@ -313,37 +313,30 @@ void test_repo_head__detaching_writes_reflog(void)
void test_repo_head__orphan_branch_does_not_count(void)
{
git_signature *sig;
git_oid id;
const char *msg;
cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
/* Have something known */
msg = "message1";
msg = "checkout: moving from master to e90810b8df3e80c413d903f631643c716887138d";
git_oid_fromstr(&id, "e90810b8df3e80c413d903f631643c716887138d");
cl_git_pass(git_repository_set_head_detached(repo, &id, msg));
cl_git_pass(git_repository_set_head_detached(repo, &id));
assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d", msg);
/* Switching to an orphan branch does not write tot he reflog */
cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan", "ignored message"));
cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan"));
assert_head_reflog(repo, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750",
"e90810b8df3e80c413d903f631643c716887138d", msg);
/* And coming back, we set the source to zero */
msg = "message2";
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", msg));
msg = "checkout: moving from orphan to haacked";
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
assert_head_reflog(repo, 0, "0000000000000000000000000000000000000000",
"258f0e2a959a364e40ed6603d5d44fbb24765b10", msg);
git_signature_free(sig);
}
void test_repo_head__set_to_current_target(void)
{
git_signature *sig;
const char *msg;
git_reflog *log;
size_t nentries, nentries_after;
......@@ -351,20 +344,14 @@ void test_repo_head__set_to_current_target(void)
nentries = git_reflog_entrycount(log);
git_reflog_free(log);
cl_git_pass(git_signature_now(&sig, "me", "foo@example.com"));
msg = "message 1";
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", msg));
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", msg));
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked"));
cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
nentries_after = git_reflog_entrycount(log);
git_reflog_free(log);
cl_assert_equal_i(nentries + 1, nentries_after);
git_signature_free(sig);
}
void test_repo_head__branch_birth(void)
......@@ -387,8 +374,7 @@ void test_repo_head__branch_birth(void)
cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJ_TREE));
git_reference_free(ref);
msg = "message 1";
cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan", msg));
cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan"));
cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE));
nentries_after = git_reflog_entrycount(log);
......
......@@ -20,7 +20,7 @@ void test_repo_headtree__cleanup(void)
void test_repo_headtree__can_retrieve_the_root_tree_from_a_detached_head(void)
{
cl_git_pass(git_repository_detach_head(repo, NULL));
cl_git_pass(git_repository_detach_head(repo));
cl_git_pass(git_repository_head_tree(&tree, repo));
......
......@@ -37,7 +37,7 @@ void test_repo_state__none_with_HEAD_attached(void)
void test_repo_state__none_with_HEAD_detached(void)
{
cl_git_pass(git_repository_detach_head(_repo, NULL));
cl_git_pass(git_repository_detach_head(_repo));
assert_repo_state(GIT_REPOSITORY_STATE_NONE);
}
......
......@@ -45,7 +45,7 @@ void test_reset_soft__can_reset_the_non_detached_Head_to_the_specified_commit(vo
void test_reset_soft__can_reset_the_detached_Head_to_the_specified_commit(void)
{
git_repository_detach_head(repo, NULL);
git_repository_detach_head(repo);
assert_reset_soft(true);
}
......@@ -118,7 +118,7 @@ void test_reset_soft__fails_when_merging(void)
{
git_buf merge_head_path = GIT_BUF_INIT;
cl_git_pass(git_repository_detach_head(repo, NULL));
cl_git_pass(git_repository_detach_head(repo));
cl_git_pass(git_buf_joinpath(&merge_head_path, git_repository_path(repo), "MERGE_HEAD"));
cl_git_mkfile(git_buf_cstr(&merge_head_path), "beefbeefbeefbeefbeefbeefbeefbeefbeefbeef\n");
......
......@@ -217,7 +217,7 @@ void test_stash_save__cannot_stash_against_a_bare_repository(void)
void test_stash_save__can_stash_against_a_detached_head(void)
{
git_repository_detach_head(repo, NULL);
git_repository_detach_head(repo);
cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));
......
......@@ -143,7 +143,7 @@ void test_status_submodules__moved_head(void)
/* move submodule HEAD to c47800c7266a2be04c571c04d5a6614691ea99bd */
cl_git_pass(
git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"));
cl_git_pass(git_repository_set_head_detached(smrepo, &oid, NULL));
cl_git_pass(git_repository_set_head_detached(smrepo, &oid));
/* first do a normal status, which should now include the submodule */
......
......@@ -89,7 +89,7 @@ void test_submodule_init__relative_url_detached_head(void)
cl_git_pass(git_repository_head(&head_ref, g_repo));
cl_git_pass(git_reference_peel(&head_commit, head_ref, GIT_OBJ_COMMIT));
cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_id((git_commit *)head_commit), NULL));
cl_git_pass(git_repository_set_head_detached(g_repo, git_commit_id((git_commit *)head_commit)));
cl_assert(git_path_dirname_r(&absolute_url, git_repository_workdir(g_repo)) > 0);
cl_git_pass(git_buf_joinpath(&absolute_url, absolute_url.ptr, "testrepo.git"));
......
......@@ -196,7 +196,7 @@ void test_submodule_update__update_already_checked_out_submodule(void)
cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1"));
cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT));
cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options));
cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference), NULL));
cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference)));
/*
* Verify state after checkout of parent repository. The submodule ID in the
......@@ -270,7 +270,7 @@ void test_submodule_update__update_blocks_on_dirty_wd(void)
cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1"));
cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT));
cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options));
cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference), NULL));
cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference)));
/*
* Verify state after checkout of parent repository. The submodule ID in the
......@@ -343,7 +343,7 @@ void test_submodule_update__can_force_update(void)
cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1"));
cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT));
cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options));
cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference), NULL));
cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference)));
/*
* Verify state after checkout of parent repository. The submodule ID in the
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment