Skip to content

Commit

Permalink
builtin/reset: compute checkout metadata for reset
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
bk2204 authored and gitster committed Mar 16, 2020
1 parent 3f26785 commit 4cf76f6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
16 changes: 13 additions & 3 deletions builtin/reset.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static inline int is_merge(void)
return !access(git_path_merge_head(the_repository), F_OK);
}

static int reset_index(const struct object_id *oid, int reset_type, int quiet)
static int reset_index(const char *ref, const struct object_id *oid, int reset_type, int quiet)
{
int i, nr = 0;
struct tree_desc desc[2];
Expand All @@ -60,6 +60,7 @@ static int reset_index(const struct object_id *oid, int reset_type, int quiet)
opts.dst_index = &the_index;
opts.fn = oneway_merge;
opts.merge = 1;
init_checkout_metadata(&opts.meta, ref, oid, NULL);
if (!quiet)
opts.verbose_update = 1;
switch (reset_type) {
Expand Down Expand Up @@ -418,11 +419,20 @@ int cmd_reset(int argc, const char **argv, const char *prefix)
}
}
} else {
int err = reset_index(&oid, reset_type, quiet);
struct object_id dummy;
char *ref = NULL;
int err;

dwim_ref(rev, strlen(rev), &dummy, &ref);
if (ref && !starts_with(ref, "refs/"))
ref = NULL;

err = reset_index(ref, &oid, reset_type, quiet);
if (reset_type == KEEP && !err)
err = reset_index(&oid, MIXED, quiet);
err = reset_index(ref, &oid, MIXED, quiet);
if (err)
die(_("Could not reset index file to revision '%s'."), rev);
free(ref);
}

if (write_locked_index(&the_index, &lock, COMMIT_LOCK))
Expand Down
32 changes: 31 additions & 1 deletion t/t0021-conversion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,8 @@ test_expect_success PERL 'required process filter should filter data for various
git commit -m "test commit 3" &&
git checkout empty-branch &&
filter_git rebase --onto empty-branch master^^ master &&
META="ref=refs/heads/master treeish=$(git rev-parse --verify master)" &&
MASTER2=$(git rev-parse --verify master) &&
META="ref=refs/heads/master treeish=$MASTER2" &&
cat >expected.log <<-EOF &&
START
init handshake complete
Expand All @@ -458,6 +459,35 @@ test_expect_success PERL 'required process filter should filter data for various
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
STOP
EOF
test_cmp_exclude_clean expected.log debug.log &&
git reset --hard empty-branch &&
filter_git reset --hard $MASTER &&
META="treeish=$MASTER" &&
cat >expected.log <<-EOF &&
START
init handshake complete
IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
STOP
EOF
test_cmp_exclude_clean expected.log debug.log &&
git branch old-master $MASTER &&
git reset --hard empty-branch &&
filter_git reset --hard old-master &&
META="ref=refs/heads/old-master treeish=$MASTER" &&
cat >expected.log <<-EOF &&
START
init handshake complete
IN: smudge test.r $META blob=$M $S [OK] -- OUT: $S . [OK]
IN: smudge test2.r $META blob=$M2 $S2 [OK] -- OUT: $S2 . [OK]
IN: smudge test4-empty.r $META blob=$EMPTY 0 [OK] -- OUT: 0 [OK]
IN: smudge testsubdir/test3 '\''sq'\'',\$x=.r $META blob=$M3 $S3 [OK] -- OUT: $S3 . [OK]
STOP
EOF
test_cmp_exclude_clean expected.log debug.log
)
'
Expand Down

0 comments on commit 4cf76f6

Please sign in to comment.