From 8be0f857e8a9faf7d8c84f314e0c4e991353878b Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 20 Jul 2019 14:52:28 -0700 Subject: [PATCH] Make autoupdate work for non-master default branches --- pre_commit/commands/autoupdate.py | 6 +++--- tests/commands/autoupdate_test.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/pre_commit/commands/autoupdate.py b/pre_commit/commands/autoupdate.py index 9701e937..fdada185 100644 --- a/pre_commit/commands/autoupdate.py +++ b/pre_commit/commands/autoupdate.py @@ -38,9 +38,9 @@ def _update_repo(repo_config, store, tags_only): """ with tmpdir() as repo_path: git.init_repo(repo_path, repo_config['repo']) - cmd_output('git', 'fetch', cwd=repo_path) + cmd_output('git', 'fetch', 'origin', 'HEAD', '--tags', cwd=repo_path) - tag_cmd = ('git', 'describe', 'origin/master', '--tags') + tag_cmd = ('git', 'describe', 'FETCH_HEAD', '--tags') if tags_only: tag_cmd += ('--abbrev=0',) else: @@ -48,7 +48,7 @@ def _update_repo(repo_config, store, tags_only): try: rev = cmd_output(*tag_cmd, cwd=repo_path)[1].strip() except CalledProcessError: - tag_cmd = ('git', 'rev-parse', 'origin/master') + tag_cmd = ('git', 'rev-parse', 'FETCH_HEAD') rev = cmd_output(*tag_cmd, cwd=repo_path)[1].strip() # Don't bother trying to update if our rev is the same diff --git a/tests/commands/autoupdate_test.py b/tests/commands/autoupdate_test.py index c1fceb42..ead0efe5 100644 --- a/tests/commands/autoupdate_test.py +++ b/tests/commands/autoupdate_test.py @@ -309,6 +309,12 @@ def test_autoupdate_hook_disappearing_repo( assert before == after +def test_autoupdate_non_master_default_branch(up_to_date_repo, store): + # change the default branch to be not-master + cmd_output('git', '-C', up_to_date_repo, 'branch', '-m', 'dev') + test_up_to_date_repo(up_to_date_repo, store) + + def test_autoupdate_local_hooks(in_git_dir, store): config = sample_local_config() add_config_to_repo('.', config)