From 2a5cbaef997063d094c8a5626c0ac2a87b93f972 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 01 2015 11:46:01 +0000 Subject: Add a method to retrieve the default branch of a git repo --- diff --git a/pagure/lib/git.py b/pagure/lib/git.py index 6acd1b9..47bd0fe 100644 --- a/pagure/lib/git.py +++ b/pagure/lib/git.py @@ -823,6 +823,16 @@ def get_base_revision(torev, fromrev, abspath): return pagure.lib.git.read_git_lines(cmd, abspath) +def get_default_branch(abspath): + """ Return the default branch of a repo. """ + cmd = ['rev-parse', '--abbrev-ref', 'HEAD'] + out = pagure.lib.git.read_git_lines(cmd, abspath) + if out: + return out[0] + else: + return 'master' + + def get_pusher(commit, abspath): ''' Return the name of the person that pushed the commit. ''' user = pagure.lib.git.read_git_lines(