@@ -1681,6 +1681,9 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
close_all_packs(the_repository->objects);
+ if (updated_refs)
+ update_server_info(-1);
+
argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL);
if (verbosity < 0)
argv_array_push(&argv_gc_auto, "--quiet");
@@ -7,6 +7,7 @@
#include "packfile.h"
#include "object-store.h"
#include "strbuf.h"
+#include "dir.h"
struct update_info_ctx {
FILE *cur_fp;
@@ -170,10 +171,25 @@ static int generate_info_refs(struct update_info_ctx *uic)
return for_each_ref(add_info_ref, uic);
}
-static int update_info_refs(int force)
+static int want_update(int *force, const char *path)
+{
+ if (*force < 0) {
+ if (file_exists(path))
+ *force = 0; /* continue to normal update */
+ else
+ return 0;
+ }
+ return 1;
+}
+
+static int update_info_refs(int *force)
{
char *path = git_pathdup("info/refs");
- int ret = update_info_file(path, generate_info_refs, force);
+ int ret = 0;
+
+ if (want_update(force, path))
+ ret = update_info_file(path, generate_info_refs, *force);
+
free(path);
return ret;
}
@@ -361,7 +377,7 @@ int update_server_info(int force)
*/
int errs = 0;
- errs = errs | update_info_refs(force);
+ errs = errs | update_info_refs(&force);
errs = errs | update_info_packs(force);
/* remove leftover rev-cache file if there is any */
@@ -27,4 +27,25 @@ test_expect_success fetch '
)
'
+test_expect_success 'info/refs not created by fetch' '
+ (
+ cd other &&
+ test_path_is_dir .git/info &&
+ ! test_path_is_file .git/info/refs
+ )
+'
+
+test_expect_success 'info/refs updated by fetch if it already exists' '
+ git branch b/for-info-refs &&
+ (
+ cd other &&
+ git update-server-info &&
+ test_path_is_file .git/info/refs &&
+ ! grep b/for-info-refs .git/info/refs &&
+ git fetch &&
+ test_path_is_file .git/info/refs &&
+ grep b/for-info-refs .git/info/refs
+ )
+'
+
test_done