Skip to content

Commit c369e7b

Browse files
iabervongitster
authored andcommitted
Move code to clean up after a branch change to branch.c
Signed-off-by: Daniel Barkalow <[email protected]>
1 parent 94a5728 commit c369e7b

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

branch.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,11 @@ void create_branch(const char *head,
138138
if (real_ref)
139139
free(real_ref);
140140
}
141+
142+
void remove_branch_state(void)
143+
{
144+
unlink(git_path("MERGE_HEAD"));
145+
unlink(git_path("rr-cache/MERGE_RR"));
146+
unlink(git_path("MERGE_MSG"));
147+
unlink(git_path("SQUASH_MSG"));
148+
}

branch.h

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
#ifndef BRANCH_H
22
#define BRANCH_H
33

4-
void create_branch(const char *head,
5-
const char *name, const char *start_name,
4+
/* Functions for acting on the information about branches. */
5+
6+
/*
7+
* Creates a new branch, where head is the branch currently checked
8+
* out, name is the new branch name, start_name is the name of the
9+
* existing branch that the new branch should start from, force
10+
* enables overwriting an existing (non-head) branch, reflog creates a
11+
* reflog for the branch, and track causes the new branch to be
12+
* configured to merge the remote branch that start_name is a tracking
13+
* branch for (if any).
14+
*/
15+
void create_branch(const char *head, const char *name, const char *start_name,
616
int force, int reflog, int track);
717

18+
/*
19+
* Remove information about the state of working on the current
20+
* branch. (E.g., MERGE_HEAD)
21+
*/
22+
void remove_branch_state(void);
23+
824
#endif

builtin-reset.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "diff.h"
1717
#include "diffcore.h"
1818
#include "tree.h"
19+
#include "branch.h"
1920

2021
static const char builtin_reset_usage[] =
2122
"git-reset [--mixed | --soft | --hard] [-q] [<commit-ish>] [ [--] <paths>...]";
@@ -270,10 +271,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
270271
break;
271272
}
272273

273-
unlink(git_path("MERGE_HEAD"));
274-
unlink(git_path("rr-cache/MERGE_RR"));
275-
unlink(git_path("MERGE_MSG"));
276-
unlink(git_path("SQUASH_MSG"));
274+
remove_branch_state();
277275

278276
free(reflog_action);
279277

0 commit comments

Comments
 (0)