Skip to content

Commit

Permalink
Merge pull request #167 from IagoAbal/develop
Browse files Browse the repository at this point in the history
Refine the heuristic used to recognize commit SHAs
  • Loading branch information
jacebrowning committed May 4, 2018
2 parents 08af065 + 322f65c commit aaf505a
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion gitman/git.py
Expand Up @@ -3,6 +3,7 @@
import os
import logging
from contextlib import suppress
import re

from . import common, settings
from .shell import call
Expand Down Expand Up @@ -47,12 +48,22 @@ def clone(repo, path, *, cache=settings.CACHE, sparse_paths=None, rev=None):
git('clone', '--reference', reference, repo, os.path.normpath(path))


def is_sha(rev):
"""Heuristically determine whether a revision corresponds to a commit SHA.
Any sequence of 7 to 40 hexadecimal digits will be recognized as a
commit SHA. The minimum of 7 digits is not an arbitrary choice, it
is the default length for short SHAs in Git.
"""
return re.match('^[0-9a-f]{7,40}$', rev) is not None


def fetch(repo, rev=None):
"""Fetch the latest changes from the remote repository."""
git('remote', 'set-url', 'origin', repo)
args = ['fetch', '--tags', '--force', '--prune', 'origin']
if rev:
if len(rev) == 40:
if is_sha(rev):
pass # fetch only works with a SHA if already present locally
elif '@' in rev:
pass # fetch doesn't work with rev-parse
Expand Down

0 comments on commit aaf505a

Please sign in to comment.