Skip to content

Commit 72549df

Browse files
peffgitster
authored andcommitted
fetch: load all default config at startup
When we start the git-fetch program, we call git_config to load all config, but our callback only processes the fetch.prune option; we do not chain to git_default_config at all. This means that we may not load some core configuration which will have an effect. For instance, we do not load core.logAllRefUpdates, which impacts whether or not we create reflogs in a bare repository. Note that I said "may" above. It gets even more exciting. If we have to transfer actual objects as part of the fetch, then we call fetch_pack as part of the same process. That function loads its own config, which does chain to git_default_config, impacting global variables which are used by the rest of fetch. But if the fetch is a pure ref update (e.g., a new ref which is a copy of an old one), we skip fetch_pack entirely. So we get inconsistent results depending on whether or not we have actual objects to transfer or not! Let's just load the core config at the start of fetch, so we know we have it (we may also load it again as part of fetch_pack, but that's OK; it's designed to be idempotent). Our tests check both cases (with and without a pack). We also check similar behavior for push for good measure, but it already works as expected. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 76f8611 commit 72549df

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

builtin/fetch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
6666
fetch_prune_config = git_config_bool(k, v);
6767
return 0;
6868
}
69-
return 0;
69+
return git_default_config(k, v, cb);
7070
}
7171

7272
static struct option builtin_fetch_options[] = {

t/t5516-fetch-push.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This test checks the following functionality:
1111
* hooks
1212
* --porcelain output format
1313
* hiderefs
14+
* reflogs
1415
'
1516

1617
. ./test-lib.sh
@@ -1277,4 +1278,43 @@ EOF
12771278
git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo
12781279
'
12791280

1281+
test_expect_success 'push into bare respects core.logallrefupdates' '
1282+
rm -rf dst.git &&
1283+
git init --bare dst.git &&
1284+
git -C dst.git config core.logallrefupdates true &&
1285+
1286+
# double push to test both with and without
1287+
# the actual pack transfer
1288+
git push dst.git master:one &&
1289+
echo "one@{0} push" >expect &&
1290+
git -C dst.git log -g --format="%gd %gs" one >actual &&
1291+
test_cmp expect actual &&
1292+
1293+
git push dst.git master:two &&
1294+
echo "two@{0} push" >expect &&
1295+
git -C dst.git log -g --format="%gd %gs" two >actual &&
1296+
test_cmp expect actual
1297+
'
1298+
1299+
test_expect_success 'fetch into bare respects core.logallrefupdates' '
1300+
rm -rf dst.git &&
1301+
git init --bare dst.git &&
1302+
(
1303+
cd dst.git &&
1304+
git config core.logallrefupdates true &&
1305+
1306+
# as above, we double-fetch to test both
1307+
# with and without pack transfer
1308+
git fetch .. master:one &&
1309+
echo "one@{0} fetch .. master:one: storing head" >expect &&
1310+
git log -g --format="%gd %gs" one >actual &&
1311+
test_cmp expect actual &&
1312+
1313+
git fetch .. master:two &&
1314+
echo "two@{0} fetch .. master:two: storing head" >expect &&
1315+
git log -g --format="%gd %gs" two >actual &&
1316+
test_cmp expect actual
1317+
)
1318+
'
1319+
12801320
test_done

0 commit comments

Comments
 (0)