Skip to content

Commit f0a7143

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

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

@@ -785,6 +785,9 @@ int cmd_update_ref(int argc,
785785
OPT_BOOL( 0 , "create-reflog", &create_reflog, N_("create a reflog")),
786786
OPT_BIT('0', "batch-updates", &flags, N_("batch reference updates"),
787787
REF_TRANSACTION_ALLOW_FAILURE),
788+
OPT_BIT(0, "initial", &flags,
789+
N_("assume the ref store is empty and skip checks"),
790+
REF_TRANSACTION_FLAG_INITIAL),
788791
OPT_HIDDEN_BOOL(0, "batch-report-early",
789792
&report_rejections_on_prepare,
790793
N_("report batch-update rejections during prepare")),
@@ -816,6 +819,8 @@ int cmd_update_ref(int argc,
816819
return 0;
817820
} else if (flags & REF_TRANSACTION_ALLOW_FAILURE) {
818821
die("--batch-updates can only be used with --stdin");
822+
} else if (flags & REF_TRANSACTION_FLAG_INITIAL) {
823+
die("--initial can only be used with --stdin");
819824
} else if (report_rejections_on_prepare) {
820825
die("--batch-report-early can only be used with --stdin");
821826
}

0 commit comments

Comments
 (0)