Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8be0f85

Browse files
committed
Make autoupdate work for non-master default branches
1 parent 7769915 commit 8be0f85

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

pre_commit/commands/autoupdate.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ def _update_repo(repo_config, store, tags_only):
3838
"""
3939
with tmpdir() as repo_path:
4040
git.init_repo(repo_path, repo_config['repo'])
41-
cmd_output('git', 'fetch', cwd=repo_path)
41+
cmd_output('git', 'fetch', 'origin', 'HEAD', '--tags', cwd=repo_path)
4242

43-
tag_cmd = ('git', 'describe', 'origin/master', '--tags')
43+
tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags')
4444
if tags_only:
4545
tag_cmd += ('--abbrev=0',)
4646
else:
4747
tag_cmd += ('--exact',)
4848
try:
4949
rev = cmd_output(*tag_cmd, cwd=repo_path)[1].strip()
5050
except CalledProcessError:
51-
tag_cmd = ('git', 'rev-parse', 'origin/master')
51+
tag_cmd = ('git', 'rev-parse', 'FETCH_HEAD')
5252
rev = cmd_output(*tag_cmd, cwd=repo_path)[1].strip()
5353

5454
# Don't bother trying to update if our rev is the same

tests/commands/autoupdate_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,12 @@ def test_autoupdate_hook_disappearing_repo(
309309
assert before == after
310310

311311

312+
def test_autoupdate_non_master_default_branch(up_to_date_repo, store):
313+
# change the default branch to be not-master
314+
cmd_output('git', '-C', up_to_date_repo, 'branch', '-m', 'dev')
315+
test_up_to_date_repo(up_to_date_repo, store)
316+
317+
312318
def test_autoupdate_local_hooks(in_git_dir, store):
313319
config = sample_local_config()
314320
add_config_to_repo('.', config)

0 commit comments

Comments
 (0)