builtin/reset: compute checkout metadata for reset
Pass the commit, and if we have it, the ref to the filters when we perform a checkout. This should only be the case when we invoke git reset --hard; the metadata will be unused otherwise. Signed-off-by: brian m. carlson <bk2204@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Mar 16, 2020 at 18:05 UTC
4cf76f6bbf8b4d7d32c7c6aec0576959c6accb63
2 files changed
+44
-4
builtin/reset.c
+13
-3
@@ -46,7 +46,7 @@ static inline int is_merge(void)
46
return !access(git_path_merge_head(the_repository), F_OK);
47
}
48
49
-static int reset_index(const struct object_id *oid, int reset_type, int quiet)
49
+static int reset_index(const char *ref, const struct object_id *oid, int reset_type, int quiet)
50
{
51
int i, nr = 0;
52
struct tree_desc desc[2];
@@ -60,6 +60,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
60
opts.dst_index = &the_index;
61
opts.fn = oneway_merge;
62
opts.merge = 1;
63
+ init_checkout_metadata(&opts.meta, ref, oid, NULL);
64
if (!quiet)
65
opts.verbose_update = 1;
66
switch (reset_type) {
@@ -418,11 +419,20 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
419
}
420
}
421
} else {
421
- int err = reset_index(&oid, reset_type, quiet);
422
+ struct object_id dummy;
423
+ char *ref = NULL;
424
+ int err;
425
+
426
+ dwim_ref(rev, strlen(rev), &dummy, &ref);
427
+ if (ref && !starts_with(ref, "refs/"))
428
+ ref = NULL;
429
+
430
+ err = reset_index(ref, &oid, reset_type, quiet);
431
if (reset_type == KEEP && !err)
423
- err = reset_index(&oid, MIXED, quiet);
432
+ err = reset_index(ref, &oid, MIXED, quiet);
433
if (err)
434
die(_("Could not reset index file to revision '%s'."), rev);
435
+ free(ref);
436
}
437
438
if (write_locked_index(&the_index, &lock, COMMIT_LOCK))
t/t0021-conversion.sh
+31
-1
@@ -447,7 +447,8 @@ test_expect_success PERL 'required process filter should filter data for various
447
git commit -m "test commit 3" &&
448
git checkout empty-branch &&
449
filter_git rebase --onto empty-branch master^^ master &&
450
- META="ref=refs/heads/master treeish=$(git rev-parse --verify master)" &&
450
+ MASTER2=$(git rev-parse --verify master) &&
451
+ META="ref=refs/heads/master treeish=$MASTER2" &&
452
cat >expected.log <<-EOF &&
453
START
454
init handshake complete
@@ -458,6 +459,35 @@ test_expect_success PERL 'required process filter should filter data for various
459
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
460
STOP
461
EOF
462
+ test_cmp_exclude_clean expected.log debug.log &&
463
+
464
+ git reset --hard empty-branch &&
465
+ filter_git reset --hard $MASTER &&
466
+ META="treeish=$MASTER" &&
467
+ cat >expected.log <<-EOF &&
468
+ START
469
+ init handshake complete
470
+ IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
471
+ IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
472
+ IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
473
+ IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
474
+ STOP
475
+ EOF
476
+ test_cmp_exclude_clean expected.log debug.log &&
477
+
478
+ git branch old-master $MASTER &&
479
+ git reset --hard empty-branch &&
480
+ filter_git reset --hard old-master &&
481
+ META="ref=refs/heads/old-master treeish=$MASTER" &&
482
+ cat >expected.log <<-EOF &&
483
+ START
484
+ init handshake complete
485
+ IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
486
+ IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
487
+ IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
488
+ IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
489
+ STOP
490
+ EOF
491
test_cmp_exclude_clean expected.log debug.log
492
)
493
'