aboutsummaryrefslogtreecommitdiffstats
path: root/branch.c
diff options
context:
space:
mode:
authorGlen Choo <chooglen@google.com>2022-01-28 16:04:43 -0800
committerJunio C Hamano <gitster@pobox.com>2022-02-01 14:18:56 -0800
commit3f3e76082bc29ff647dff16de9f0145a4d582825 (patch)
tree202f07a599663c3f9659920b2051018852899a1c /branch.c
parentbc0893cf3b0ee376ef5b6ed293b1525480a9d720 (diff)
downloadgit-3f3e76082bc29ff647dff16de9f0145a4d582825.tar.gz
branch: add a dry_run parameter to create_branch()
Add a dry_run parameter to create_branch() such that dry_run = 1 will validate a new branch without trying to create it. This will be used in `git branch --recurse-submodules` to ensure that the new branch can be created in all submodules. Signed-off-by: Glen Choo <chooglen@google.com> Reviewed-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'branch.c')
-rw-r--r--branch.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/branch.c b/branch.c
index df24021f27..02d46a69b8 100644
--- a/branch.c
+++ b/branch.c
@@ -423,7 +423,7 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
void create_branch(struct repository *r,
const char *name, const char *start_name,
int force, int clobber_head_ok, int reflog,
- int quiet, enum branch_track track)
+ int quiet, enum branch_track track, int dry_run)
{
struct object_id oid;
char *real_ref;
@@ -445,6 +445,8 @@ void create_branch(struct repository *r,
}
dwim_branch_start(r, start_name, track, &real_ref, &oid);
+ if (dry_run)
+ goto cleanup;
if (reflog)
log_all_ref_updates = LOG_REFS_NORMAL;
@@ -467,6 +469,7 @@ void create_branch(struct repository *r,
if (real_ref && track)
setup_tracking(ref.buf + 11, real_ref, track, quiet);
+cleanup:
strbuf_release(&ref);
free(real_ref);
}