Skip to content

Commit

Permalink
fix: changes made according to pull request review #214
Browse files Browse the repository at this point in the history
  • Loading branch information
Felipe P. Silva committed Aug 21, 2021
1 parent 82cf124 commit 0f09984
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
15 changes: 7 additions & 8 deletions peru/resources/plugins/git/git_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import configparser
import hashlib
import os
import re
import subprocess
import sys

Expand Down Expand Up @@ -181,20 +180,20 @@ def git_default_branch(url) -> str:
str: returns a possible match for the git default branch.
"""
repo_path = clone_if_needed(url)
default_branches_list = ['master', 'main', 'trunk', 'development']
default_branches_list = ['master', 'main']
for branch in default_branches_list:
output = git(
'branch', '-a', git_dir=repo_path, capture_output=True).output
parse_output = re.search(r'' + re.escape(branch) + '', output)
if parse_output:
output = git('show-ref', '--verify', '--quiet', 'refs/heads/' + branch,
git_dir=repo_path, checked=False, capture_output=True)
if output.returncode == 0:
return branch
return 'master'


def main():
URL = os.environ['PERU_MODULE_URL']
REV = os.environ['PERU_MODULE_REV'] or git_default_branch(URL)
REUP = os.environ['PERU_MODULE_REUP'] or git_default_branch(URL)
default_branch = git_default_branch(URL)
REV = os.environ['PERU_MODULE_REV'] or default_branch
REUP = os.environ['PERU_MODULE_REUP'] or default_branch

command = os.environ['PERU_PLUGIN_COMMAND']
if command == 'sync':
Expand Down
12 changes: 6 additions & 6 deletions tests/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,14 @@ def run(self, *command):


class GitRepo(Repo):
def __init__(self, content_dir, **init_default_branch):
def __init__(self, content_dir, init_default_branch=None):
super().__init__(content_dir)

self.run('git', 'init')
# includes option to change the initial default branch
if 'default_branch' in init_default_branch:
self.run('git', 'symbolic-ref',
'HEAD', 'refs/heads/' + init_default_branch['default_branch'])a
branch_args = []
if init_default_branch is not None:
branch_args = ['--initial-branch', init_default_branch]
# Note the * character. This has no effect if the list is empty.
self.run('git', 'init', *branch_args)
self.run('git', 'config', 'user.name', 'peru')
self.run('git', 'config', 'user.email', 'peru')
self.run('git', 'add', '-A')
Expand Down
2 changes: 1 addition & 1 deletion tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_git_plugin(self):
self.do_plugin_test("git", {"url": self.content_dir}, self.content)

def test_git_default_branch(self):
GitRepo(self.content_dir, default_branch='main')
GitRepo(self.content_dir, init_default_branch='main')
self.do_plugin_test("git", {"url": self.content_dir}, self.content)

def test_empty_git_rev(self):
Expand Down

0 comments on commit 0f09984

Please sign in to comment.