Skip to content

Commit 9f1384f

Browse files
committed
Merge branch 'jk/quarantine-received-objects'
Add finishing touches to a recent topic. * jk/quarantine-received-objects: refs: reject ref updates while GIT_QUARANTINE_PATH is set receive-pack: document user-visible quarantine effects receive-pack: drop tmp_objdir_env from run_update_hook
2 parents d7f8a37 + d8f4481 commit 9f1384f

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed

Documentation/git-receive-pack.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ will be performed, and the update, post-receive and post-update
114114
hooks will not be invoked either. This can be useful to quickly
115115
bail out if the update is not to be supported.
116116

117+
See the notes on the quarantine environment below.
118+
117119
update Hook
118120
-----------
119121
Before each ref is updated, if $GIT_DIR/hooks/update file exists
@@ -214,6 +216,33 @@ if the repository is packed and is served via a dumb transport.
214216
exec git update-server-info
215217

216218

219+
Quarantine Environment
220+
----------------------
221+
222+
When `receive-pack` takes in objects, they are placed into a temporary
223+
"quarantine" directory within the `$GIT_DIR/objects` directory and
224+
migrated into the main object store only after the `pre-receive` hook
225+
has completed. If the push fails before then, the temporary directory is
226+
removed entirely.
227+
228+
This has a few user-visible effects and caveats:
229+
230+
1. Pushes which fail due to problems with the incoming pack, missing
231+
objects, or due to the `pre-receive` hook will not leave any
232+
on-disk data. This is usually helpful to prevent repeated failed
233+
pushes from filling up your disk, but can make debugging more
234+
challenging.
235+
236+
2. Any objects created by the `pre-receive` hook will be created in
237+
the quarantine directory (and migrated only if it succeeds).
238+
239+
3. The `pre-receive` hook MUST NOT update any refs to point to
240+
quarantined objects. Other programs accessing the repository will
241+
not be able to see the objects (and if the pre-receive hook fails,
242+
those refs would become corrupted). For safety, any ref updates
243+
from within `pre-receive` are automatically rejected.
244+
245+
217246
SEE ALSO
218247
--------
219248
linkgit:git-send-pack[1], linkgit:gitnamespaces[7]

Documentation/githooks.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ environment variables will not be set. If the client selects
256256
to use push options, but doesn't transmit any, the count variable
257257
will be set to zero, `GIT_PUSH_OPTION_COUNT=0`.
258258

259+
See the section on "Quarantine Environment" in
260+
linkgit:git-receive-pack[1] for some caveats.
261+
259262
[[update]]
260263
update
261264
~~~~~~

builtin/receive-pack.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,6 @@ static int run_update_hook(struct command *cmd)
772772
proc.stdout_to_stderr = 1;
773773
proc.err = use_sideband ? -1 : 0;
774774
proc.argv = argv;
775-
proc.env = tmp_objdir_env(tmp_objdir);
776775

777776
code = start_command(&proc);
778777
if (code)

refs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1643,6 +1643,12 @@ int ref_transaction_commit(struct ref_transaction *transaction,
16431643
{
16441644
struct ref_store *refs = transaction->ref_store;
16451645

1646+
if (getenv(GIT_QUARANTINE_ENVIRONMENT)) {
1647+
strbuf_addstr(err,
1648+
_("ref updates forbidden inside quarantine environment"));
1649+
return -1;
1650+
}
1651+
16461652
return refs->be->transaction_commit(refs, transaction, err);
16471653
}
16481654

t/t5547-push-quarantine.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,15 @@ test_expect_success 'push to repo path with path separator (colon)' '
5858
git push "$(pwd)/xxx${pathsep}yyy.git" HEAD
5959
'
6060

61+
test_expect_success 'updating a ref from quarantine is forbidden' '
62+
git init --bare update.git &&
63+
write_script update.git/hooks/pre-receive <<-\EOF &&
64+
read old new refname
65+
git update-ref refs/heads/unrelated $new
66+
exit 1
67+
EOF
68+
test_must_fail git push update.git HEAD &&
69+
git -C update.git fsck
70+
'
71+
6172
test_done

0 commit comments

Comments
 (0)