]> git.ipfire.org Git - thirdparty/git.git/blobdiff - branch.c
object-name.h: move declarations for object-name.c functions from cache.h
[thirdparty/git.git] / branch.c
index 5aaf073dce130ec77f94cfce1ccb3cc74a58179b..f29743b161972dea2df79b55aaa7d7289c09ee95 100644 (file)
--- a/branch.c
+++ b/branch.c
@@ -1,8 +1,12 @@
 #include "git-compat-util.h"
 #include "cache.h"
+#include "advice.h"
 #include "config.h"
 #include "branch.h"
+#include "environment.h"
+#include "gettext.h"
 #include "hex.h"
+#include "object-name.h"
 #include "refs.h"
 #include "refspec.h"
 #include "remote.h"
@@ -532,7 +536,7 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
                explicit_tracking = 1;
 
        real_ref = NULL;
-       if (get_oid_mb(start_name, &oid)) {
+       if (repo_get_oid_mb(r, start_name, &oid)) {
                if (explicit_tracking) {
                        int code = die_message(_(upstream_missing), start_name);
                        advise_if_enabled(ADVICE_SET_UPSTREAM_FAILURE,
@@ -542,7 +546,8 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
                die(_("not a valid object name: '%s'"), start_name);
        }
 
-       switch (dwim_ref(start_name, strlen(start_name), &oid, &real_ref, 0)) {
+       switch (repo_dwim_ref(r, start_name, strlen(start_name), &oid,
+                             &real_ref, 0)) {
        case 0:
                /* Not branching from any existing branch */
                if (explicit_tracking)
@@ -773,7 +778,7 @@ void create_branches_recursively(struct repository *r, const char *name,
                            name);
        }
 
-       create_branch(the_repository, name, start_commitish, force, 0, reflog, quiet,
+       create_branch(r, name, start_commitish, force, 0, reflog, quiet,
                      BRANCH_TRACK_NEVER, dry_run);
        if (dry_run)
                return;
@@ -821,12 +826,16 @@ void remove_branch_state(struct repository *r, int verbose)
 void die_if_checked_out(const char *branch, int ignore_current_worktree)
 {
        struct worktree **worktrees = get_worktrees();
-       const struct worktree *wt;
 
-       wt = find_shared_symref(worktrees, "HEAD", branch);
-       if (wt && (!ignore_current_worktree || !wt->is_current)) {
-               skip_prefix(branch, "refs/heads/", &branch);
-               die(_("'%s' is already checked out at '%s'"), branch, wt->path);
+       for (int i = 0; worktrees[i]; i++) {
+               if (worktrees[i]->is_current && ignore_current_worktree)
+                       continue;
+
+               if (is_shared_symref(worktrees[i], "HEAD", branch)) {
+                       skip_prefix(branch, "refs/heads/", &branch);
+                       die(_("'%s' is already checked out at '%s'"),
+                               branch, worktrees[i]->path);
+               }
        }
 
        free_worktrees(worktrees);