1515from pre_commit .logging_handler import LoggingHandler
1616from pre_commit .ordereddict import OrderedDict
1717from pre_commit .repository import Repository
18+ from pre_commit .util import CalledProcessError
1819from pre_commit .util import cmd_output
1920from pre_commit .util import cwd
2021
@@ -38,15 +39,20 @@ def _update_repository(repo_config, runner):
3839
3940 with cwd (repo .repo_path_getter .repo_path ):
4041 cmd_output ('git' , 'fetch' )
41- head_sha = cmd_output ('git' , 'rev-parse' , 'origin/master' )[1 ].strip ()
42+ try :
43+ rev = cmd_output (
44+ 'git' , 'describe' , 'origin/master' , '--tags' , '--exact' ,
45+ )[1 ].strip ()
46+ except CalledProcessError :
47+ rev = cmd_output ('git' , 'rev-parse' , 'origin/master' )[1 ].strip ()
4248
4349 # Don't bother trying to update if our sha is the same
44- if head_sha == repo_config ['sha' ]:
50+ if rev == repo_config ['sha' ]:
4551 return repo_config
4652
4753 # Construct a new config with the head sha
4854 new_config = OrderedDict (repo_config )
49- new_config ['sha' ] = head_sha
55+ new_config ['sha' ] = rev
5056 new_repo = Repository .create (new_config , runner .store )
5157
5258 # See if any of our hooks were deleted with the new commits
0 commit comments