Error out when user doesn't have access permission to the repository
Signed-off-by: André Goddard Rosa <andre.goddard@gmail.com>
André Goddard Rosa committed
Nov 22, 2007 at 20:22 UTC
d6617c7cdebc20fe007e983f70b44a223dd52c28
2 files changed
+24
-7
builtin-fetch--tool.c
+10
-2
@@ -511,10 +511,14 @@ int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
511
if (!strcmp("append-fetch-head", argv[1])) {
512
int result;
513
FILE *fp;
514
+ char *filename;
515
516
if (argc != 8)
517
return error("append-fetch-head takes 6 args");
517
- fp = fopen(git_path("FETCH_HEAD"), "a");
518
+ filename = git_path("FETCH_HEAD");
519
+ fp = fopen(filename, "a");
520
+ if (!fp)
521
+ return error("cannot open %s: %s\n", filename, strerror(errno));
522
result = append_fetch_head(fp, argv[2], argv[3],
523
argv[4], argv[5],
524
argv[6], !!argv[7][0],
@@ -525,10 +529,14 @@ int cmd_fetch__tool(int argc, const char **argv, const char *prefix)
529
if (!strcmp("native-store", argv[1])) {
530
int result;
531
FILE *fp;
532
+ char *filename;
533
534
if (argc != 5)
535
return error("fetch-native-store takes 3 args");
531
- fp = fopen(git_path("FETCH_HEAD"), "a");
536
+ filename = git_path("FETCH_HEAD");
537
+ fp = fopen(filename, "a");
538
+ if (!fp)
539
+ return error("cannot open %s: %s\n", filename, strerror(errno));
540
result = fetch_native_store(fp, argv[2], argv[3], argv[4],
541
verbose, force);
542
fclose(fp);
builtin-fetch.c
+14
-5
@@ -255,7 +255,7 @@ static int update_local_ref(struct ref *ref,
255
}
256
}
257
258
-static void store_updated_refs(const char *url, struct ref *ref_map)
258
+static int store_updated_refs(const char *url, struct ref *ref_map)
259
{
260
FILE *fp;
261
struct commit *commit;
@@ -263,8 +263,11 @@ static void store_updated_refs(const char *url, struct ref *ref_map)
263
char note[1024];
264
const char *what, *kind;
265
struct ref *rm;
266
+ char *filename = git_path("FETCH_HEAD");
267
267
- fp = fopen(git_path("FETCH_HEAD"), "a");
268
+ fp = fopen(filename, "a");
269
+ if (!fp)
270
+ return error("cannot open %s: %s\n", filename, strerror(errno));
271
for (rm = ref_map; rm; rm = rm->next) {
272
struct ref *ref = NULL;
273
@@ -335,6 +338,7 @@ static void store_updated_refs(const char *url, struct ref *ref_map)
338
}
339
}
340
fclose(fp);
341
+ return 0;
342
}
343
344
/*
@@ -404,7 +408,7 @@ static int fetch_refs(struct transport *transport, struct ref *ref_map)
408
if (ret)
409
ret = transport_fetch_refs(transport, ref_map);
410
if (!ret)
407
- store_updated_refs(transport->url, ref_map);
411
+ ret |= store_updated_refs(transport->url, ref_map);
412
transport_unlock_pack(transport);
413
return ret;
414
}
@@ -487,8 +491,13 @@ static int do_fetch(struct transport *transport,
491
die("Don't know how to fetch from %s", transport->url);
492
493
/* if not appending, truncate FETCH_HEAD */
490
- if (!append)
491
- fclose(fopen(git_path("FETCH_HEAD"), "w"));
494
+ if (!append) {
495
+ char *filename = git_path("FETCH_HEAD");
496
+ FILE *fp = fopen(filename, "w");
497
+ if (!fp)
498
+ return error("cannot open %s: %s\n", filename, strerror(errno));
499
+ fclose(fp);
500
+ }
501
502
ref_map = get_ref_map(transport, refs, ref_count, tags, &autotags);
503