]> git.ipfire.org Git - thirdparty/git.git/blame - builtin-receive-pack.c
Makefile: add compat/bswap.h to LIB_H
[thirdparty/git.git] / builtin-receive-pack.c
CommitLineData
575f4974 1#include "cache.h"
fc04c412 2#include "pack.h"
8a65ff76 3#include "refs.h"
f3a3214e 4#include "pkt-line.h"
b1bf95bb 5#include "run-command.h"
576162a4 6#include "exec_cmd.h"
11031d7e
JS
7#include "commit.h"
8#include "object.h"
d79796bc
JH
9#include "remote.h"
10#include "transport.h"
575f4974 11
34263de0 12static const char receive_pack_usage[] = "git receive-pack <git-dir>";
575f4974 13
986e8239 14enum deny_action {
3d95d92b 15 DENY_UNCONFIGURED,
986e8239
JK
16 DENY_IGNORE,
17 DENY_WARN,
18 DENY_REFUSE,
19};
20
1b53a076
JH
21static int deny_deletes;
22static int deny_non_fast_forwards;
3d95d92b 23static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
747ca245 24static enum deny_action deny_delete_current = DENY_UNCONFIGURED;
20dc0016 25static int receive_fsck_objects;
e28714c5
JH
26static int receive_unpack_limit = -1;
27static int transfer_unpack_limit = -1;
46732fae 28static int unpack_limit = 100;
96f1e58f 29static int report_status;
b74fce16 30static int prefer_ofs_delta = 1;
747ca245 31static const char *head_name;
b74fce16 32static char *capabilities_to_send;
cfee10a7 33
986e8239
JK
34static enum deny_action parse_deny_action(const char *var, const char *value)
35{
36 if (value) {
37 if (!strcasecmp(value, "ignore"))
38 return DENY_IGNORE;
39 if (!strcasecmp(value, "warn"))
40 return DENY_WARN;
41 if (!strcasecmp(value, "refuse"))
42 return DENY_REFUSE;
43 }
44 if (git_config_bool(var, value))
45 return DENY_REFUSE;
46 return DENY_IGNORE;
47}
48
ef90d6d4 49static int receive_pack_config(const char *var, const char *value, void *cb)
6fb75bed 50{
a240de11
JK
51 if (strcmp(var, "receive.denydeletes") == 0) {
52 deny_deletes = git_config_bool(var, value);
53 return 0;
54 }
55
e28714c5 56 if (strcmp(var, "receive.denynonfastforwards") == 0) {
6fb75bed
SP
57 deny_non_fast_forwards = git_config_bool(var, value);
58 return 0;
59 }
60
e28714c5
JH
61 if (strcmp(var, "receive.unpacklimit") == 0) {
62 receive_unpack_limit = git_config_int(var, value);
fc04c412
SP
63 return 0;
64 }
65
e28714c5
JH
66 if (strcmp(var, "transfer.unpacklimit") == 0) {
67 transfer_unpack_limit = git_config_int(var, value);
68 return 0;
69 }
70
20dc0016
MK
71 if (strcmp(var, "receive.fsckobjects") == 0) {
72 receive_fsck_objects = git_config_bool(var, value);
73 return 0;
74 }
75
986e8239
JK
76 if (!strcmp(var, "receive.denycurrentbranch")) {
77 deny_current_branch = parse_deny_action(var, value);
78 return 0;
79 }
80
747ca245
JH
81 if (strcmp(var, "receive.denydeletecurrent") == 0) {
82 deny_delete_current = parse_deny_action(var, value);
83 return 0;
84 }
85
b74fce16
NP
86 if (strcmp(var, "repack.usedeltabaseoffset") == 0) {
87 prefer_ofs_delta = git_config_bool(var, value);
88 return 0;
89 }
90
ef90d6d4 91 return git_default_config(var, value, cb);
6fb75bed
SP
92}
93
8da19775 94static int show_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)
575f4974 95{
b74fce16 96 if (!capabilities_to_send)
cfee10a7
JH
97 packet_write(1, "%s %s\n", sha1_to_hex(sha1), path);
98 else
99 packet_write(1, "%s %s%c%s\n",
b74fce16
NP
100 sha1_to_hex(sha1), path, 0, capabilities_to_send);
101 capabilities_to_send = NULL;
8a65ff76 102 return 0;
575f4974
LT
103}
104
8a65ff76 105static void write_head_info(void)
575f4974 106{
cb5d709f 107 for_each_ref(show_ref, NULL);
b74fce16 108 if (capabilities_to_send)
8da19775 109 show_ref("capabilities^{}", null_sha1, 0, NULL);
cfee10a7 110
575f4974
LT
111}
112
eb1af2df
LT
113struct command {
114 struct command *next;
cfee10a7 115 const char *error_string;
eb1af2df
LT
116 unsigned char old_sha1[20];
117 unsigned char new_sha1[20];
8f1d2e6f 118 char ref_name[FLEX_ARRAY]; /* more */
575f4974
LT
119};
120
96f1e58f 121static struct command *commands;
575f4974 122
05ef58ec
SP
123static const char pre_receive_hook[] = "hooks/pre-receive";
124static const char post_receive_hook[] = "hooks/post-receive";
b1bf95bb 125
ae98a008 126static int run_receive_hook(const char *hook_name)
b1bf95bb 127{
f43cd49f 128 static char buf[sizeof(commands->old_sha1) * 2 + PATH_MAX + 4];
c8dd2771 129 struct command *cmd;
f43cd49f
SP
130 struct child_process proc;
131 const char *argv[2];
132 int have_input = 0, code;
c8dd2771 133
f43cd49f 134 for (cmd = commands; !have_input && cmd; cmd = cmd->next) {
c8dd2771 135 if (!cmd->error_string)
f43cd49f 136 have_input = 1;
c8dd2771 137 }
b1bf95bb 138
f43cd49f 139 if (!have_input || access(hook_name, X_OK) < 0)
b1bf95bb 140 return 0;
c8dd2771 141
c8dd2771 142 argv[0] = hook_name;
f43cd49f
SP
143 argv[1] = NULL;
144
145 memset(&proc, 0, sizeof(proc));
146 proc.argv = argv;
147 proc.in = -1;
148 proc.stdout_to_stderr = 1;
149
150 code = start_command(&proc);
151 if (code)
90e41a89 152 return code;
f43cd49f 153 for (cmd = commands; cmd; cmd = cmd->next) {
c8dd2771 154 if (!cmd->error_string) {
f43cd49f
SP
155 size_t n = snprintf(buf, sizeof(buf), "%s %s %s\n",
156 sha1_to_hex(cmd->old_sha1),
157 sha1_to_hex(cmd->new_sha1),
158 cmd->ref_name);
159 if (write_in_full(proc.in, buf, n) != n)
160 break;
c8dd2771 161 }
c8dd2771 162 }
e72ae288 163 close(proc.in);
90e41a89 164 return finish_command(&proc);
b1bf95bb
JW
165}
166
1d9e8b56
SP
167static int run_update_hook(struct command *cmd)
168{
169 static const char update_hook[] = "hooks/update";
1d9e8b56
SP
170 const char *argv[5];
171
172 if (access(update_hook, X_OK) < 0)
173 return 0;
174
175 argv[0] = update_hook;
176 argv[1] = cmd->ref_name;
177 argv[2] = sha1_to_hex(cmd->old_sha1);
178 argv[3] = sha1_to_hex(cmd->new_sha1);
179 argv[4] = NULL;
180
90e41a89
JS
181 return run_command_v_opt(argv, RUN_COMMAND_NO_STDIN |
182 RUN_COMMAND_STDOUT_TO_STDERR);
1d9e8b56
SP
183}
184
986e8239
JK
185static int is_ref_checked_out(const char *ref)
186{
986e8239
JK
187 if (is_bare_repository())
188 return 0;
189
747ca245 190 if (!head_name)
986e8239 191 return 0;
747ca245 192 return !strcmp(head_name, ref);
986e8239
JK
193}
194
3d95d92b
JH
195static char *warn_unconfigured_deny_msg[] = {
196 "Updating the currently checked out branch may cause confusion,",
197 "as the index and work tree do not reflect changes that are in HEAD.",
198 "As a result, you may see the changes you just pushed into it",
199 "reverted when you run 'git diff' over there, and you may want",
200 "to run 'git reset --hard' before starting to work to recover.",
201 "",
202 "You can set 'receive.denyCurrentBranch' configuration variable to",
203 "'refuse' in the remote repository to forbid pushing into its",
204 "current branch."
205 "",
206 "To allow pushing into the current branch, you can set it to 'ignore';",
207 "but this is not recommended unless you arranged to update its work",
208 "tree to match what you pushed in some other way.",
209 "",
210 "To squelch this message, you can set it to 'warn'.",
211 "",
212 "Note that the default will change in a future version of git",
213 "to refuse updating the current branch unless you have the",
214 "configuration variable set to either 'ignore' or 'warn'."
215};
216
217static void warn_unconfigured_deny(void)
218{
219 int i;
220 for (i = 0; i < ARRAY_SIZE(warn_unconfigured_deny_msg); i++)
88a667f0 221 warning("%s", warn_unconfigured_deny_msg[i]);
3d95d92b
JH
222}
223
747ca245
JH
224static char *warn_unconfigured_deny_delete_current_msg[] = {
225 "Deleting the current branch can cause confusion by making the next",
226 "'git clone' not check out any file.",
227 "",
228 "You can set 'receive.denyDeleteCurrent' configuration variable to",
229 "'refuse' in the remote repository to disallow deleting the current",
230 "branch.",
231 "",
232 "You can set it to 'ignore' to allow such a delete without a warning.",
233 "",
234 "To make this warning message less loud, you can set it to 'warn'.",
235 "",
236 "Note that the default will change in a future version of git",
237 "to refuse deleting the current branch unless you have the",
238 "configuration variable set to either 'ignore' or 'warn'."
239};
240
241static void warn_unconfigured_deny_delete_current(void)
242{
243 int i;
244 for (i = 0;
245 i < ARRAY_SIZE(warn_unconfigured_deny_delete_current_msg);
246 i++)
88a667f0 247 warning("%s", warn_unconfigured_deny_delete_current_msg[i]);
747ca245
JH
248}
249
8aaf7d64 250static const char *update(struct command *cmd)
2eca23da 251{
cfee10a7
JH
252 const char *name = cmd->ref_name;
253 unsigned char *old_sha1 = cmd->old_sha1;
254 unsigned char *new_sha1 = cmd->new_sha1;
3159c8dc 255 struct ref_lock *lock;
2eca23da 256
061d6b9a
MK
257 /* only refs/... are allowed */
258 if (prefixcmp(name, "refs/") || check_ref_format(name + 5)) {
0b8293f6 259 error("refusing to create funny ref '%s' remotely", name);
8aaf7d64 260 return "funny refname";
cfee10a7 261 }
d8a1deec 262
3d95d92b
JH
263 if (is_ref_checked_out(name)) {
264 switch (deny_current_branch) {
265 case DENY_IGNORE:
986e8239 266 break;
3d95d92b
JH
267 case DENY_UNCONFIGURED:
268 case DENY_WARN:
269 warning("updating the current branch");
270 if (deny_current_branch == DENY_UNCONFIGURED)
271 warn_unconfigured_deny();
986e8239 272 break;
3d95d92b
JH
273 case DENY_REFUSE:
274 error("refusing to update checked out branch: %s", name);
275 return "branch is currently checked out";
276 }
986e8239
JK
277 }
278
d4f694ba 279 if (!is_null_sha1(new_sha1) && !has_sha1_file(new_sha1)) {
8aaf7d64
SP
280 error("unpack should have generated %s, "
281 "but I can't find it!", sha1_to_hex(new_sha1));
282 return "bad pack";
cfee10a7 283 }
747ca245
JH
284
285 if (!is_null_sha1(old_sha1) && is_null_sha1(new_sha1)) {
286 if (deny_deletes && !prefixcmp(name, "refs/heads/")) {
287 error("denying ref deletion for %s", name);
288 return "deletion prohibited";
289 }
290
291 if (!strcmp(name, head_name)) {
292 switch (deny_delete_current) {
293 case DENY_IGNORE:
294 break;
295 case DENY_WARN:
296 case DENY_UNCONFIGURED:
297 if (deny_delete_current == DENY_UNCONFIGURED)
298 warn_unconfigured_deny_delete_current();
299 warning("deleting the current branch");
300 break;
301 case DENY_REFUSE:
302 error("refusing to delete the current branch: %s", name);
303 return "deletion of the current branch prohibited";
304 }
305 }
a240de11 306 }
747ca245 307
d4f694ba 308 if (deny_non_fast_forwards && !is_null_sha1(new_sha1) &&
ba988a83 309 !is_null_sha1(old_sha1) &&
cc44c765 310 !prefixcmp(name, "refs/heads/")) {
eab82707 311 struct object *old_object, *new_object;
11031d7e 312 struct commit *old_commit, *new_commit;
9edd7e46 313 struct commit_list *bases, *ent;
11031d7e 314
eab82707
MK
315 old_object = parse_object(old_sha1);
316 new_object = parse_object(new_sha1);
317
318 if (!old_object || !new_object ||
319 old_object->type != OBJ_COMMIT ||
320 new_object->type != OBJ_COMMIT) {
321 error("bad sha1 objects for %s", name);
322 return "bad ref";
323 }
324 old_commit = (struct commit *)old_object;
325 new_commit = (struct commit *)new_object;
9edd7e46
JS
326 bases = get_merge_bases(old_commit, new_commit, 1);
327 for (ent = bases; ent; ent = ent->next)
328 if (!hashcmp(old_sha1, ent->item->object.sha1))
11031d7e 329 break;
9edd7e46 330 free_commit_list(bases);
8aaf7d64
SP
331 if (!ent) {
332 error("denying non-fast forward %s"
333 " (you should pull first)", name);
334 return "non-fast forward";
335 }
11031d7e 336 }
1d9e8b56 337 if (run_update_hook(cmd)) {
8aaf7d64
SP
338 error("hook declined to update %s", name);
339 return "hook declined";
b1bf95bb 340 }
3159c8dc 341
d4f694ba 342 if (is_null_sha1(new_sha1)) {
28391a80
JS
343 if (!parse_object(old_sha1)) {
344 warning ("Allowing deletion of corrupt ref.");
345 old_sha1 = NULL;
346 }
eca35a25 347 if (delete_ref(name, old_sha1, 0)) {
8aaf7d64
SP
348 error("failed to delete %s", name);
349 return "failed to delete";
d4f694ba 350 }
8aaf7d64 351 return NULL; /* good */
d4f694ba
JH
352 }
353 else {
68db31cc 354 lock = lock_any_ref_for_update(name, old_sha1, 0);
d4f694ba 355 if (!lock) {
8aaf7d64
SP
356 error("failed to lock %s", name);
357 return "failed to lock";
d4f694ba 358 }
ef203f08 359 if (write_ref_sha1(lock, new_sha1, "push")) {
8aaf7d64 360 return "failed to write"; /* error() already called */
ef203f08 361 }
8aaf7d64 362 return NULL; /* good */
19614330 363 }
2eca23da
LT
364}
365
19614330
JH
366static char update_post_hook[] = "hooks/post-update";
367
368static void run_update_post_hook(struct command *cmd)
369{
370 struct command *cmd_p;
2ff4d1ab 371 int argc, status;
9201c707 372 const char **argv;
19614330 373
3e6e152c 374 for (argc = 0, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) {
cfee10a7 375 if (cmd_p->error_string)
19614330
JH
376 continue;
377 argc++;
378 }
3e6e152c
SP
379 if (!argc || access(update_post_hook, X_OK) < 0)
380 return;
381 argv = xmalloc(sizeof(*argv) * (2 + argc));
19614330
JH
382 argv[0] = update_post_hook;
383
384 for (argc = 1, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) {
9201c707 385 char *p;
cfee10a7 386 if (cmd_p->error_string)
19614330 387 continue;
9201c707
JH
388 p = xmalloc(strlen(cmd_p->ref_name) + 1);
389 strcpy(p, cmd_p->ref_name);
390 argv[argc] = p;
19614330
JH
391 argc++;
392 }
393 argv[argc] = NULL;
2ff4d1ab
JS
394 status = run_command_v_opt(argv, RUN_COMMAND_NO_STDIN
395 | RUN_COMMAND_STDOUT_TO_STDERR);
19614330 396}
2eca23da 397
8aaf7d64 398static void execute_commands(const char *unpacker_error)
575f4974 399{
eb1af2df 400 struct command *cmd = commands;
747ca245 401 unsigned char sha1[20];
8aaf7d64
SP
402
403 if (unpacker_error) {
404 while (cmd) {
405 cmd->error_string = "n/a (unpacker error)";
406 cmd = cmd->next;
407 }
408 return;
409 }
410
ae98a008 411 if (run_receive_hook(pre_receive_hook)) {
05ef58ec
SP
412 while (cmd) {
413 cmd->error_string = "pre-receive hook declined";
414 cmd = cmd->next;
415 }
416 return;
417 }
418
747ca245
JH
419 head_name = resolve_ref("HEAD", sha1, 0, NULL);
420
eb1af2df 421 while (cmd) {
8aaf7d64 422 cmd->error_string = update(cmd);
eb1af2df 423 cmd = cmd->next;
575f4974
LT
424 }
425}
426
427static void read_head_info(void)
428{
eb1af2df 429 struct command **p = &commands;
575f4974
LT
430 for (;;) {
431 static char line[1000];
eb1af2df
LT
432 unsigned char old_sha1[20], new_sha1[20];
433 struct command *cmd;
cfee10a7
JH
434 char *refname;
435 int len, reflen;
eb1af2df
LT
436
437 len = packet_read_line(0, line, sizeof(line));
575f4974
LT
438 if (!len)
439 break;
eb1af2df
LT
440 if (line[len-1] == '\n')
441 line[--len] = 0;
442 if (len < 83 ||
443 line[40] != ' ' ||
444 line[81] != ' ' ||
445 get_sha1_hex(line, old_sha1) ||
446 get_sha1_hex(line + 41, new_sha1))
cfee10a7
JH
447 die("protocol error: expected old/new/ref, got '%s'",
448 line);
449
450 refname = line + 82;
451 reflen = strlen(refname);
452 if (reflen + 82 < len) {
453 if (strstr(refname + reflen + 1, "report-status"))
454 report_status = 1;
455 }
eb1af2df 456 cmd = xmalloc(sizeof(struct command) + len - 80);
e702496e
SP
457 hashcpy(cmd->old_sha1, old_sha1);
458 hashcpy(cmd->new_sha1, new_sha1);
eb1af2df 459 memcpy(cmd->ref_name, line + 82, len - 81);
8aaf7d64 460 cmd->error_string = NULL;
eb1af2df
LT
461 cmd->next = NULL;
462 *p = cmd;
463 p = &cmd->next;
575f4974
LT
464 }
465}
466
fc04c412
SP
467static const char *parse_pack_header(struct pack_header *hdr)
468{
a69e5429
JH
469 switch (read_pack_header(0, hdr)) {
470 case PH_ERROR_EOF:
471 return "eof before pack header was fully read";
472
473 case PH_ERROR_PACK_SIGNATURE:
fc04c412 474 return "protocol error (pack signature mismatch detected)";
a69e5429
JH
475
476 case PH_ERROR_PROTOCOL:
fc04c412 477 return "protocol error (pack version unsupported)";
a69e5429
JH
478
479 default:
480 return "unknown error in parse_pack_header";
481
482 case 0:
483 return NULL;
484 }
fc04c412
SP
485}
486
576162a4
NP
487static const char *pack_lockfile;
488
861ed121 489static const char *unpack(void)
575f4974 490{
fc04c412
SP
491 struct pack_header hdr;
492 const char *hdr_err;
493 char hdr_arg[38];
fc04c412
SP
494
495 hdr_err = parse_pack_header(&hdr);
496 if (hdr_err)
497 return hdr_err;
6e1c2344
RJ
498 snprintf(hdr_arg, sizeof(hdr_arg),
499 "--pack_header=%"PRIu32",%"PRIu32,
fc04c412
SP
500 ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries));
501
502 if (ntohl(hdr.hdr_entries) < unpack_limit) {
20dc0016
MK
503 int code, i = 0;
504 const char *unpacker[4];
505 unpacker[i++] = "unpack-objects";
506 if (receive_fsck_objects)
507 unpacker[i++] = "--strict";
508 unpacker[i++] = hdr_arg;
509 unpacker[i++] = NULL;
9b0b5093 510 code = run_command_v_opt(unpacker, RUN_GIT_CMD);
2ff4d1ab 511 if (!code)
fc04c412 512 return NULL;
2ff4d1ab 513 return "unpack-objects abnormal exit";
576162a4 514 } else {
20dc0016
MK
515 const char *keeper[7];
516 int s, status, i = 0;
576162a4 517 char keep_arg[256];
e8016abf 518 struct child_process ip;
576162a4 519
85e72830 520 s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid());
576162a4
NP
521 if (gethostname(keep_arg + s, sizeof(keep_arg) - s))
522 strcpy(keep_arg + s, "localhost");
523
20dc0016
MK
524 keeper[i++] = "index-pack";
525 keeper[i++] = "--stdin";
526 if (receive_fsck_objects)
527 keeper[i++] = "--strict";
528 keeper[i++] = "--fix-thin";
529 keeper[i++] = hdr_arg;
530 keeper[i++] = keep_arg;
531 keeper[i++] = NULL;
e8016abf
SP
532 memset(&ip, 0, sizeof(ip));
533 ip.argv = keeper;
534 ip.out = -1;
535 ip.git_cmd = 1;
2ff4d1ab
JS
536 status = start_command(&ip);
537 if (status) {
576162a4 538 return "index-pack fork failed";
2ff4d1ab 539 }
106764e6 540 pack_lockfile = index_pack_lockfile(ip.out);
e72ae288 541 close(ip.out);
e8016abf
SP
542 status = finish_command(&ip);
543 if (!status) {
576162a4
NP
544 reprepare_packed_git();
545 return NULL;
546 }
547 return "index-pack abnormal exit";
cfee10a7
JH
548 }
549}
550
551static void report(const char *unpack_status)
552{
553 struct command *cmd;
554 packet_write(1, "unpack %s\n",
555 unpack_status ? unpack_status : "ok");
556 for (cmd = commands; cmd; cmd = cmd->next) {
557 if (!cmd->error_string)
558 packet_write(1, "ok %s\n",
559 cmd->ref_name);
560 else
561 packet_write(1, "ng %s %s\n",
562 cmd->ref_name, cmd->error_string);
575f4974 563 }
cfee10a7 564 packet_flush(1);
575f4974
LT
565}
566
d4f694ba
JH
567static int delete_only(struct command *cmd)
568{
569 while (cmd) {
570 if (!is_null_sha1(cmd->new_sha1))
571 return 0;
572 cmd = cmd->next;
573 }
574 return 1;
575}
576
d79796bc
JH
577static int add_refs_from_alternate(struct alternate_object_database *e, void *unused)
578{
b8492539
JH
579 char *other;
580 size_t len;
d79796bc
JH
581 struct remote *remote;
582 struct transport *transport;
583 const struct ref *extra;
584
b8492539
JH
585 e->name[-1] = '\0';
586 other = xstrdup(make_absolute_path(e->base));
587 e->name[-1] = '/';
588 len = strlen(other);
589
d79796bc
JH
590 while (other[len-1] == '/')
591 other[--len] = '\0';
592 if (len < 8 || memcmp(other + len - 8, "/objects", 8))
593 return 0;
594 /* Is this a git repository with refs? */
595 memcpy(other + len - 8, "/refs", 6);
596 if (!is_directory(other))
597 return 0;
598 other[len - 8] = '\0';
599 remote = remote_get(other);
600 transport = transport_get(remote, other);
601 for (extra = transport_get_remote_refs(transport);
602 extra;
603 extra = extra->next) {
604 add_extra_ref(".have", extra->old_sha1, 0);
605 }
606 transport_disconnect(transport);
607 free(other);
608 return 0;
609}
610
611static void add_alternate_refs(void)
612{
613 foreach_alt_odb(add_refs_from_alternate, NULL);
614}
615
be5908ae 616int cmd_receive_pack(int argc, const char **argv, const char *prefix)
575f4974 617{
d0efc8a7 618 int i;
8d630132 619 char *dir = NULL;
575f4974
LT
620
621 argv++;
622 for (i = 1; i < argc; i++) {
be5908ae 623 const char *arg = *argv++;
575f4974
LT
624
625 if (*arg == '-') {
575f4974
LT
626 /* Do flag handling here */
627 usage(receive_pack_usage);
628 }
d0efc8a7
LT
629 if (dir)
630 usage(receive_pack_usage);
be5908ae 631 dir = xstrdup(arg);
575f4974
LT
632 }
633 if (!dir)
634 usage(receive_pack_usage);
635
e1464ca7 636 setup_path();
5c09f321 637
3159c8dc 638 if (!enter_repo(dir, 0))
05ac6b34 639 die("'%s' does not appear to be a git repository", dir);
575f4974 640
a0022eeb
JH
641 if (is_repository_shallow())
642 die("attempt to push into a shallow repository");
643
ef90d6d4 644 git_config(receive_pack_config, NULL);
6fb75bed 645
e28714c5
JH
646 if (0 <= transfer_unpack_limit)
647 unpack_limit = transfer_unpack_limit;
648 else if (0 <= receive_unpack_limit)
649 unpack_limit = receive_unpack_limit;
650
b74fce16
NP
651 capabilities_to_send = (prefer_ofs_delta) ?
652 " report-status delete-refs ofs-delta " :
653 " report-status delete-refs ";
654
d79796bc 655 add_alternate_refs();
8a65ff76 656 write_head_info();
d79796bc 657 clear_extra_refs();
575f4974
LT
658
659 /* EOF */
f3a3214e 660 packet_flush(1);
575f4974
LT
661
662 read_head_info();
7f8e9828 663 if (commands) {
d4f694ba
JH
664 const char *unpack_status = NULL;
665
666 if (!delete_only(commands))
667 unpack_status = unpack();
8aaf7d64 668 execute_commands(unpack_status);
576162a4 669 if (pack_lockfile)
691f1a28 670 unlink_or_warn(pack_lockfile);
cfee10a7
JH
671 if (report_status)
672 report(unpack_status);
ae98a008 673 run_receive_hook(post_receive_hook);
8e663d9e 674 run_update_post_hook(commands);
7f8e9828 675 }
575f4974
LT
676 return 0;
677}