summaryrefslogtreecommitdiff
path: root/branch.c
diff options
context:
space:
mode:
Diffstat (limited to 'branch.c')
-rw-r--r--branch.c28
1 files changed, 20 insertions, 8 deletions
diff --git a/branch.c b/branch.c
index b0024353f4..7ff3f20496 100644
--- a/branch.c
+++ b/branch.c
@@ -4,6 +4,7 @@
#include "refs.h"
#include "remote.h"
#include "commit.h"
+#include "worktree.h"
struct tracking {
struct refspec spec;
@@ -266,7 +267,7 @@ void create_branch(const char *head,
if ((commit = lookup_commit_reference(sha1)) == NULL)
die(_("Not a valid branch point: '%s'."), start_name);
- hashcpy(sha1, commit->object.sha1);
+ hashcpy(sha1, commit->object.oid.hash);
if (forcing)
snprintf(msg, sizeof msg, "branch: Reset to %s",
@@ -302,11 +303,22 @@ void create_branch(const char *head,
void remove_branch_state(void)
{
- unlink(git_path("CHERRY_PICK_HEAD"));
- unlink(git_path("REVERT_HEAD"));
- unlink(git_path("MERGE_HEAD"));
- unlink(git_path("MERGE_RR"));
- unlink(git_path("MERGE_MSG"));
- unlink(git_path("MERGE_MODE"));
- unlink(git_path("SQUASH_MSG"));
+ unlink(git_path_cherry_pick_head());
+ unlink(git_path_revert_head());
+ unlink(git_path_merge_head());
+ unlink(git_path_merge_rr());
+ unlink(git_path_merge_msg());
+ unlink(git_path_merge_mode());
+ unlink(git_path_squash_msg());
+}
+
+void die_if_checked_out(const char *branch)
+{
+ char *existing;
+
+ existing = find_shared_symref("HEAD", branch);
+ if (existing) {
+ skip_prefix(branch, "refs/heads/", &branch);
+ die(_("'%s' is already checked out at '%s'"), branch, existing);
+ }
}