Skip to content

Commit cf62b9b

Browse files
committed
update-ref: implement --initial
Signed-off-by: Vicent Marti <vmg@strn.cat>
1 parent f47b052 commit cf62b9b

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

Documentation/git-update-ref.adoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
[synopsis]
1111
git update-ref [-m <reason>] [--no-deref] -d <ref> [<old-oid>]
1212
git update-ref [-m <reason>] [--no-deref] [--create-reflog] <ref> <new-oid> [<old-oid>]
13-
git update-ref [-m <reason>] [--no-deref] --stdin [-z] [--batch-updates]
13+
git update-ref [-m <reason>] [--no-deref] --stdin [-z] [--initial] [--batch-updates]
1414

1515
DESCRIPTION
1616
-----------
@@ -59,6 +59,13 @@ performs all modifications together. Specify commands of the form:
5959
With `--create-reflog`, update-ref will create a reflog for each ref
6060
even if one would not ordinarily be created.
6161

62+
With `--initial`, update-ref assumes the ref store is empty and skips the
63+
checks that detect conflicts with existing references, writing the queued
64+
updates as an initial bulk load. This is only valid when no references
65+
exist yet (for example, immediately after `git init`); using it against a
66+
populated ref store is unsupported. It can only be used together with
67+
`--stdin`.
68+
6269
With `--batch-updates`, update-ref executes the updates in a batch but allows
6370
individual updates to fail due to invalid or incorrect user input, applying only
6471
the successful updates. However, system-related errors—such as I/O failures or

builtin/update-ref.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
static const char * const git_update_ref_usage[] = {
1616
N_("git update-ref [<options>] -d <refname> [<old-oid>]"),
1717
N_("git update-ref [<options>] <refname> <new-oid> [<old-oid>]"),
18-
N_("git update-ref [<options>] --stdin [-z] [--batch-updates]"),
18+
N_("git update-ref [<options>] --stdin [-z] [--initial] [--batch-updates]"),
1919
NULL
2020
};
2121

@@ -842,6 +842,9 @@ int cmd_update_ref(int argc,
842842
OPT_BOOL( 0 , "create-reflog", &create_reflog, N_("create a reflog")),
843843
OPT_BIT('0', "batch-updates", &flags, N_("batch reference updates"),
844844
REF_TRANSACTION_ALLOW_FAILURE),
845+
OPT_BIT(0, "initial", &flags,
846+
N_("assume the ref store is empty and skip checks"),
847+
REF_TRANSACTION_FLAG_INITIAL),
845848
OPT_HIDDEN_BOOL(0, "batch-report-early",
846849
&report_rejections_on_prepare,
847850
N_("report batch-update rejections during prepare")),
@@ -873,6 +876,8 @@ int cmd_update_ref(int argc,
873876
return 0;
874877
} else if (flags & REF_TRANSACTION_ALLOW_FAILURE) {
875878
die("--batch-updates can only be used with --stdin");
879+
} else if (flags & REF_TRANSACTION_FLAG_INITIAL) {
880+
die("--initial can only be used with --stdin");
876881
} else if (report_rejections_on_prepare) {
877882
die("--batch-report-early can only be used with --stdin");
878883
}

0 commit comments

Comments
 (0)