filter-repo: handle reset to specific ref and deletion

The reset directive can specify a commit hash for the 'from' directive,
which can be used to reset to a specify commit, or, if the hash is all
zeros, then it can be used to delete the ref.  Support such operations.

Signed-off-by: Elijah Newren <newren@gmail.com>
pull/13/head
Elijah Newren 5 years ago
parent 0b70b72150
commit 4c25fe7a37

@ -534,7 +534,10 @@ class Reset(_GitElement):
file_.write(b'reset %s\n' % self.ref)
if self.from_ref:
file_.write(b'from :%d\n' % self.from_ref)
if isinstance(self.from_ref, int):
file_.write(b'from :%d\n' % self.from_ref)
else:
file_.write(b'from %s\n' % self.from_ref)
file_.write(b'\n')
class FileChange(_GitElement):
@ -3066,6 +3069,8 @@ class RepoFilter(object):
# Record we've seen this ref and don't need to force a manual update
# for it.
self._seen_refs[reset.ref] = None
if isinstance(reset.from_ref, bytes) and re.match(b'^0+$', reset.from_ref):
del self._seen_refs[reset.ref]
def results_tmp_dir(self, create_if_missing=True):
working_dir = self._args.target or self._args.source or b'.'

@ -950,6 +950,29 @@ test_expect_success 'incremental import' '
)
'
test_expect_success 'reset to specific refs' '
test_create_repo reset_to_specific_refs &&
(
cd reset_to_specific_refs &&
git commit --allow-empty -m initial &&
INITIAL=$(git rev-parse HEAD) &&
echo "$INITIAL refs/heads/develop" >expect &&
cat >input <<-INPUT_END &&
reset refs/heads/develop
from $INITIAL
reset refs/heads/master
from 0000000000000000000000000000000000000000
INPUT_END
cat input | git filter-repo --force --stdin &&
git show-ref >actual &&
test_cmp expect actual
)
'
test_expect_success 'setup handle funny characters' '
test_create_repo funny_chars &&
(

Loading…
Cancel
Save