From 605da51a2cfd86901b6fa5f9cf71111a63ab4418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 17 Sep 2013 09:50:30 +0200 Subject: [PATCH] No such thing as an orphan branch Unfortunately git-core uses the term "unborn branch" and "orphan branch" interchangeably. However, "orphan" is only really there for the checkout command, which has the `--orphan` option so it doesn't actually create the branch. Branches never have parents, so the distinction of a branch with no parents is odd to begin with. Crucially, the error messages deal with unborn branches, so let's use that. --- examples/status.c | 2 +- include/git2/checkout.h | 2 +- include/git2/errors.h | 2 +- include/git2/repository.h | 12 ++++++------ src/branch.c | 2 +- src/checkout.c | 2 +- src/clone.c | 2 +- src/remote.c | 2 +- src/repository.c | 6 +++--- src/stash.c | 2 +- src/status.c | 2 +- src/submodule.c | 2 +- tests-clar/checkout/head.c | 6 +++--- tests-clar/clone/empty.c | 4 ++-- tests-clar/clone/nonetwork.c | 2 +- tests-clar/online/clone.c | 2 +- tests-clar/refs/branches/delete.c | 4 ++-- tests-clar/refs/branches/ishead.c | 4 ++-- tests-clar/repo/head.c | 26 +++++++++++++------------- tests-clar/repo/headtree.c | 8 ++++---- tests-clar/repo/repo_helpers.c | 2 +- tests-clar/repo/repo_helpers.h | 2 +- tests-clar/reset/soft.c | 8 ++++---- tests-clar/stash/save.c | 2 +- tests-clar/submodule/lookup.c | 10 +++++----- 25 files changed, 59 insertions(+), 59 deletions(-) diff --git a/examples/status.c b/examples/status.c index 689098415..0d9f55f13 100644 --- a/examples/status.c +++ b/examples/status.c @@ -71,7 +71,7 @@ static void show_branch(git_repository *repo, int format) error = git_repository_head(&head, repo); - if (error == GIT_EORPHANEDHEAD || error == GIT_ENOTFOUND) + if (error == GIT_EUNBORNBRANCH || error == GIT_ENOTFOUND) branch = NULL; else if (!error) { branch = git_reference_name(head); diff --git a/include/git2/checkout.h b/include/git2/checkout.h index a086408c7..aa48069cd 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -249,7 +249,7 @@ typedef struct git_checkout_opts { * * @param repo repository to check out (must be non-bare) * @param opts specifies checkout options (may be NULL) - * @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing + * @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing * branch, GIT_ERROR otherwise (use giterr_last for information * about the error) */ diff --git a/include/git2/errors.h b/include/git2/errors.h index 0f0bddf07..dd566440c 100644 --- a/include/git2/errors.h +++ b/include/git2/errors.h @@ -27,7 +27,7 @@ typedef enum { GIT_EBUFS = -6, GIT_EUSER = -7, GIT_EBAREREPO = -8, - GIT_EORPHANEDHEAD = -9, + GIT_EUNBORNBRANCH = -9, GIT_EUNMERGED = -10, GIT_ENONFASTFORWARD = -11, GIT_EINVALIDSPEC = -12, diff --git a/include/git2/repository.h b/include/git2/repository.h index 807d834fe..b4d561992 100644 --- a/include/git2/repository.h +++ b/include/git2/repository.h @@ -297,7 +297,7 @@ GIT_EXTERN(int) git_repository_init_ext( * @param out pointer to the reference which will be retrieved * @param repo a repository object * - * @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing + * @return 0 on success, GIT_EUNBORNBRANCH when HEAD points to a non existing * branch, GIT_ENOTFOUND when HEAD is missing; an error code otherwise */ GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo); @@ -315,16 +315,16 @@ GIT_EXTERN(int) git_repository_head(git_reference **out, git_repository *repo); GIT_EXTERN(int) git_repository_head_detached(git_repository *repo); /** - * Check if the current branch is an orphan + * Check if the current branch is unborn * - * An orphan branch is one named from HEAD but which doesn't exist in + * An unborn branch is one named from HEAD but which doesn't exist in * the refs namespace, because it doesn't have any commit to point to. * * @param repo Repo to test - * @return 1 if the current branch is an orphan, 0 if it's not; error + * @return 1 if the current branch is unborn, 0 if it's not; error * code if there was an error */ -GIT_EXTERN(int) git_repository_head_orphan(git_repository *repo); +GIT_EXTERN(int) git_repository_head_unborn(git_repository *repo); /** * Check if a repository is empty @@ -611,7 +611,7 @@ GIT_EXTERN(int) git_repository_set_head_detached( * Otherwise, the HEAD will be detached and point to the peeled Commit. * * @param repo Repository pointer - * @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing + * @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( diff --git a/src/branch.c b/src/branch.c index 7064fa7fc..3a745c127 100644 --- a/src/branch.c +++ b/src/branch.c @@ -585,7 +585,7 @@ int git_branch_is_head( error = git_repository_head(&head, git_reference_owner(branch)); - if (error == GIT_EORPHANEDHEAD || error == GIT_ENOTFOUND) + if (error == GIT_EUNBORNBRANCH || error == GIT_ENOTFOUND) return false; if (error < 0) diff --git a/src/checkout.c b/src/checkout.c index aae354ca6..eb92e8fd6 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -1232,7 +1232,7 @@ static int checkout_data_init( error = checkout_lookup_head_tree(&data->opts.baseline, repo); - if (error == GIT_EORPHANEDHEAD) { + if (error == GIT_EUNBORNBRANCH) { error = 0; giterr_clear(); } diff --git a/src/clone.c b/src/clone.c index 9f47e07b6..ff251be1b 100644 --- a/src/clone.c +++ b/src/clone.c @@ -415,7 +415,7 @@ static bool should_checkout( if (opts->checkout_strategy == GIT_CHECKOUT_NONE) return false; - return !git_repository_head_orphan(repo); + return !git_repository_head_unborn(repo); } static void normalize_options(git_clone_options *dst, const git_clone_options *src, git_repository_init_options *initOptions) diff --git a/src/remote.c b/src/remote.c index bdc8e0e67..bfcb3eb65 100644 --- a/src/remote.c +++ b/src/remote.c @@ -806,7 +806,7 @@ static int remote_head_for_ref(git_remote_head **out, git_refspec *spec, git_vec (!git_reference_is_branch(resolved_ref)) || (error = git_branch_upstream(&tracking_ref, resolved_ref)) < 0 || (error = git_refspec_transform_l(&remote_name, spec, git_reference_name(tracking_ref))) < 0) { - /* Not an error if HEAD is orphaned or no tracking branch */ + /* Not an error if HEAD is unborn or no tracking branch */ if (error == GIT_ENOTFOUND) error = 0; diff --git a/src/repository.c b/src/repository.c index eae22ce51..eead41201 100644 --- a/src/repository.c +++ b/src/repository.c @@ -1451,10 +1451,10 @@ int git_repository_head(git_reference **head_out, git_repository *repo) error = git_reference_lookup_resolved(head_out, repo, git_reference_symbolic_target(head), -1); git_reference_free(head); - return error == GIT_ENOTFOUND ? GIT_EORPHANEDHEAD : error; + return error == GIT_ENOTFOUND ? GIT_EUNBORNBRANCH : error; } -int git_repository_head_orphan(git_repository *repo) +int git_repository_head_unborn(git_repository *repo) { git_reference *ref = NULL; int error; @@ -1462,7 +1462,7 @@ int git_repository_head_orphan(git_repository *repo) error = git_repository_head(&ref, repo); git_reference_free(ref); - if (error == GIT_EORPHANEDHEAD) + if (error == GIT_EUNBORNBRANCH) return 1; if (error < 0) diff --git a/src/stash.c b/src/stash.c index 48f19144d..ab4a68575 100644 --- a/src/stash.c +++ b/src/stash.c @@ -27,7 +27,7 @@ static int retrieve_head(git_reference **out, git_repository *repo) { int error = git_repository_head(out, repo); - if (error == GIT_EORPHANEDHEAD) + if (error == GIT_EUNBORNBRANCH) return create_error(error, "You do not have the initial commit yet."); return error; diff --git a/src/status.c b/src/status.c index 4a0d65092..be40b9f83 100644 --- a/src/status.c +++ b/src/status.c @@ -252,7 +252,7 @@ int git_status_list_new( /* if there is no HEAD, that's okay - we'll make an empty iterator */ if (((error = git_repository_head_tree(&head, repo)) < 0) && - error != GIT_ENOTFOUND && error != GIT_EORPHANEDHEAD) { + error != GIT_ENOTFOUND && error != GIT_EUNBORNBRANCH) { git_index_free(index); /* release index */ return error; } diff --git a/src/submodule.c b/src/submodule.c index 40bda9a41..121383b9c 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -1557,7 +1557,7 @@ static void submodule_get_wd_status( if (ign == GIT_SUBMODULE_IGNORE_NONE) opt.flags |= GIT_DIFF_INCLUDE_UNTRACKED; - /* if we don't have an orphaned head, check diff with index */ + /* if we don't have an unborn head, check diff with index */ if (git_repository_head_tree(&sm_head, sm_repo) < 0) giterr_clear(); else { diff --git a/tests-clar/checkout/head.c b/tests-clar/checkout/head.c index 46646f8bf..74c6fb87a 100644 --- a/tests-clar/checkout/head.c +++ b/tests-clar/checkout/head.c @@ -16,11 +16,11 @@ void test_checkout_head__cleanup(void) cl_git_sandbox_cleanup(); } -void test_checkout_head__orphaned_head_returns_GIT_EORPHANEDHEAD(void) +void test_checkout_head__unborn_head_returns_GIT_EUNBORNBRANCH(void) { - make_head_orphaned(g_repo, NON_EXISTING_HEAD); + make_head_unborn(g_repo, NON_EXISTING_HEAD); - cl_assert_equal_i(GIT_EORPHANEDHEAD, git_checkout_head(g_repo, NULL)); + cl_assert_equal_i(GIT_EUNBORNBRANCH, git_checkout_head(g_repo, NULL)); } void test_checkout_head__with_index_only_tree(void) diff --git a/tests-clar/clone/empty.c b/tests-clar/clone/empty.c index f92fa6cbb..d9dc24fde 100644 --- a/tests-clar/clone/empty.c +++ b/tests-clar/clone/empty.c @@ -44,7 +44,7 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void) g_options.bare = true; cl_git_pass(git_clone(&g_repo_cloned, "./empty_bare.git", "./empty", &g_options)); - /* Although the HEAD is orphaned... */ + /* Although the HEAD is unborn... */ cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, local_name)); /* ...one can still retrieve the name of the remote tracking reference */ @@ -59,7 +59,7 @@ void test_clone_empty__can_clone_an_empty_local_repo_barely(void) cl_assert_equal_s(expected_remote_name, buffer); - /* ...even when the remote HEAD is orphaned as well */ + /* ...even when the remote HEAD is unborn as well */ cl_assert_equal_i(GIT_ENOTFOUND, git_reference_lookup(&ref, g_repo_cloned, expected_tracked_branch_name)); } diff --git a/tests-clar/clone/nonetwork.c b/tests-clar/clone/nonetwork.c index 339b1e70d..5b9faa645 100644 --- a/tests-clar/clone/nonetwork.c +++ b/tests-clar/clone/nonetwork.c @@ -228,7 +228,7 @@ void test_clone_nonetwork__can_checkout_given_branch(void) g_options.checkout_branch = "test"; cl_git_pass(git_clone(&g_repo, cl_git_fixture_url("testrepo.git"), "./foo", &g_options)); - cl_assert_equal_i(0, git_repository_head_orphan(g_repo)); + cl_assert_equal_i(0, git_repository_head_unborn(g_repo)); cl_git_pass(git_repository_head(&g_ref, g_repo)); cl_assert_equal_s(git_reference_name(g_ref), "refs/heads/test"); diff --git a/tests-clar/online/clone.c b/tests-clar/online/clone.c index bc4285a00..dc5aa4150 100644 --- a/tests-clar/online/clone.c +++ b/tests-clar/online/clone.c @@ -69,7 +69,7 @@ void test_online_clone__empty_repository(void) cl_git_pass(git_clone(&g_repo, LIVE_EMPTYREPO_URL, "./foo", &g_options)); cl_assert_equal_i(true, git_repository_is_empty(g_repo)); - cl_assert_equal_i(true, git_repository_head_orphan(g_repo)); + cl_assert_equal_i(true, git_repository_head_unborn(g_repo)); cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE)); cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head)); diff --git a/tests-clar/refs/branches/delete.c b/tests-clar/refs/branches/delete.c index 7af5a3e86..de90cb734 100644 --- a/tests-clar/refs/branches/delete.c +++ b/tests-clar/refs/branches/delete.c @@ -57,11 +57,11 @@ void test_refs_branches_delete__can_delete_a_branch_even_if_HEAD_is_missing(void git_reference_free(branch); } -void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_orphaned(void) +void test_refs_branches_delete__can_delete_a_branch_when_HEAD_is_unborn(void) { git_reference *branch; - make_head_orphaned(repo, NON_EXISTING_HEAD); + make_head_unborn(repo, NON_EXISTING_HEAD); cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL)); cl_git_pass(git_branch_delete(branch)); diff --git a/tests-clar/refs/branches/ishead.c b/tests-clar/refs/branches/ishead.c index dfcf1b5f1..b1ad09c3e 100644 --- a/tests-clar/refs/branches/ishead.c +++ b/tests-clar/refs/branches/ishead.c @@ -26,13 +26,13 @@ void test_refs_branches_ishead__can_tell_if_a_branch_is_pointed_at_by_HEAD(void) cl_assert_equal_i(true, git_branch_is_head(branch)); } -void test_refs_branches_ishead__can_properly_handle_orphaned_HEAD(void) +void test_refs_branches_ishead__can_properly_handle_unborn_HEAD(void) { git_repository_free(repo); repo = cl_git_sandbox_init("testrepo.git"); - make_head_orphaned(repo, NON_EXISTING_HEAD); + make_head_unborn(repo, NON_EXISTING_HEAD); cl_git_pass(git_reference_lookup(&branch, repo, "refs/heads/master")); diff --git a/tests-clar/repo/head.c b/tests-clar/repo/head.c index a9f5cfc58..5a55984bd 100644 --- a/tests-clar/repo/head.c +++ b/tests-clar/repo/head.c @@ -32,20 +32,20 @@ void test_repo_head__head_detached(void) cl_assert_equal_i(false, git_repository_head_detached(repo)); } -void test_repo_head__head_orphan(void) +void test_repo_head__unborn_head(void) { git_reference *ref; cl_git_pass(git_repository_head_detached(repo)); - make_head_orphaned(repo, NON_EXISTING_HEAD); + make_head_unborn(repo, NON_EXISTING_HEAD); - cl_assert(git_repository_head_orphan(repo) == 1); + cl_assert(git_repository_head_unborn(repo) == 1); /* take the repo back to it's original state */ cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", 1)); - cl_assert(git_repository_head_orphan(repo) == 0); + cl_assert(git_repository_head_unborn(repo) == 0); git_reference_free(ref); } @@ -58,7 +58,7 @@ void test_repo_head__set_head_Attaches_HEAD_to_un_unborn_branch_when_the_branch_ cl_assert_equal_i(false, git_repository_head_detached(repo)); - cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head(&head, repo)); + cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head(&head, repo)); } void test_repo_head__set_head_Returns_ENOTFOUND_when_the_reference_doesnt_exist(void) @@ -163,20 +163,20 @@ void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void git_reference_free(head); } -void test_repo_head__detaching_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void) +void test_repo_head__detaching_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void) { - make_head_orphaned(repo, NON_EXISTING_HEAD); + make_head_unborn(repo, NON_EXISTING_HEAD); - cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_detach_head(repo)); + cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_detach_head(repo)); } -void test_repo_head__retrieving_an_orphaned_head_returns_GIT_EORPHANEDHEAD(void) +void test_repo_head__retrieving_an_unborn_branch_returns_GIT_EUNBORNBRANCH(void) { git_reference *head; - make_head_orphaned(repo, NON_EXISTING_HEAD); + make_head_unborn(repo, NON_EXISTING_HEAD); - cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head(&head, repo)); + cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head(&head, repo)); } void test_repo_head__retrieving_a_missing_head_returns_GIT_ENOTFOUND(void) @@ -188,9 +188,9 @@ void test_repo_head__retrieving_a_missing_head_returns_GIT_ENOTFOUND(void) cl_assert_equal_i(GIT_ENOTFOUND, git_repository_head(&head, repo)); } -void test_repo_head__can_tell_if_an_orphaned_head_is_detached(void) +void test_repo_head__can_tell_if_an_unborn_head_is_detached(void) { - make_head_orphaned(repo, NON_EXISTING_HEAD); + make_head_unborn(repo, NON_EXISTING_HEAD); cl_assert_equal_i(false, git_repository_head_detached(repo)); } diff --git a/tests-clar/repo/headtree.c b/tests-clar/repo/headtree.c index 0e7fe93e5..e899ac399 100644 --- a/tests-clar/repo/headtree.c +++ b/tests-clar/repo/headtree.c @@ -36,13 +36,13 @@ void test_repo_headtree__can_retrieve_the_root_tree_from_a_non_detached_head(voi cl_assert(git_oid_streq(git_tree_id(tree), "az")); } -void test_repo_headtree__when_head_is_orphaned_returns_EORPHANEDHEAD(void) +void test_repo_headtree__when_head_is_unborn_returns_EUNBORNBRANCH(void) { - make_head_orphaned(repo, NON_EXISTING_HEAD); + make_head_unborn(repo, NON_EXISTING_HEAD); - cl_assert_equal_i(true, git_repository_head_orphan(repo)); + cl_assert_equal_i(true, git_repository_head_unborn(repo)); - cl_assert_equal_i(GIT_EORPHANEDHEAD, git_repository_head_tree(&tree, repo)); + cl_assert_equal_i(GIT_EUNBORNBRANCH, git_repository_head_tree(&tree, repo)); } void test_repo_headtree__when_head_is_missing_returns_ENOTFOUND(void) diff --git a/tests-clar/repo/repo_helpers.c b/tests-clar/repo/repo_helpers.c index 74902e439..3d477ff42 100644 --- a/tests-clar/repo/repo_helpers.c +++ b/tests-clar/repo/repo_helpers.c @@ -3,7 +3,7 @@ #include "repo_helpers.h" #include "posix.h" -void make_head_orphaned(git_repository* repo, const char *target) +void make_head_unborn(git_repository* repo, const char *target) { git_reference *head; diff --git a/tests-clar/repo/repo_helpers.h b/tests-clar/repo/repo_helpers.h index 09b5cac84..6783d5701 100644 --- a/tests-clar/repo/repo_helpers.h +++ b/tests-clar/repo/repo_helpers.h @@ -2,5 +2,5 @@ #define NON_EXISTING_HEAD "refs/heads/hide/and/seek" -extern void make_head_orphaned(git_repository* repo, const char *target); +extern void make_head_unborn(git_repository* repo, const char *target); extern void delete_head(git_repository* repo); diff --git a/tests-clar/reset/soft.c b/tests-clar/reset/soft.c index 884697c91..bd6fcc205 100644 --- a/tests-clar/reset/soft.c +++ b/tests-clar/reset/soft.c @@ -95,19 +95,19 @@ void test_reset_soft__cannot_reset_to_a_tag_not_pointing_at_a_commit(void) cl_git_fail(git_reset(repo, target, GIT_RESET_SOFT)); } -void test_reset_soft__resetting_against_an_orphaned_head_repo_makes_the_head_no_longer_orphaned(void) +void test_reset_soft__resetting_against_an_unborn_head_repo_makes_the_head_no_longer_unborn(void) { git_reference *head; retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO); - make_head_orphaned(repo, NON_EXISTING_HEAD); + make_head_unborn(repo, NON_EXISTING_HEAD); - cl_assert_equal_i(true, git_repository_head_orphan(repo)); + cl_assert_equal_i(true, git_repository_head_unborn(repo)); cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT)); - cl_assert_equal_i(false, git_repository_head_orphan(repo)); + cl_assert_equal_i(false, git_repository_head_unborn(repo)); cl_git_pass(git_reference_lookup(&head, repo, NON_EXISTING_HEAD)); cl_assert_equal_i(0, git_oid_streq(git_reference_target(head), KNOWN_COMMIT_IN_BARE_REPO)); diff --git a/tests-clar/stash/save.c b/tests-clar/stash/save.c index eae116ac5..bb35a3d71 100644 --- a/tests-clar/stash/save.c +++ b/tests-clar/stash/save.c @@ -194,7 +194,7 @@ void test_stash_save__cannot_stash_against_an_unborn_branch(void) cl_git_pass(git_reference_symbolic_create(&head, repo, "HEAD", "refs/heads/unborn", 1)); - cl_assert_equal_i(GIT_EORPHANEDHEAD, + cl_assert_equal_i(GIT_EUNBORNBRANCH, git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT)); git_reference_free(head); diff --git a/tests-clar/submodule/lookup.c b/tests-clar/submodule/lookup.c index 013bbdf96..b626cdf04 100644 --- a/tests-clar/submodule/lookup.c +++ b/tests-clar/submodule/lookup.c @@ -114,15 +114,15 @@ void test_submodule_lookup__foreach(void) cl_assert_equal_i(8, data.count); } -void test_submodule_lookup__lookup_even_with_orphaned_head(void) +void test_submodule_lookup__lookup_even_with_unborn_head(void) { - git_reference *orphan; + git_reference *head; git_submodule *sm; - /* orphan the head */ + /* put us on an unborn branch */ cl_git_pass(git_reference_symbolic_create( - &orphan, g_repo, "HEAD", "refs/heads/garbage", 1)); - git_reference_free(orphan); + &head, g_repo, "HEAD", "refs/heads/garbage", 1)); + git_reference_free(head); /* lookup existing */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged"));