From a86823b5df8deb6b91973f8b4858885c0883b4e6 Mon Sep 17 00:00:00 2001 From: Konstantin Ryabitsev Date: Mon, 11 Feb 2019 18:00:15 -0500 Subject: Look up shortname refs in proper order We were not using proper order when looking up remote refs, for details see this thread: https://lore.kernel.org/lkml/CAHk-=wg9yvP3hGVRSnc=8qoj0g7_zt=_2FjmgSAu-0DViyFtaw@mail.gmail.com This fix changes the order to properly match heads and be more correct when handling shortnames in general. Signed-off-by: Konstantin Ryabitsev --- pr-tracker-bot.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/pr-tracker-bot.py b/pr-tracker-bot.py index 4ee0854..b58cacb 100755 --- a/pr-tracker-bot.py +++ b/pr-tracker-bot.py @@ -196,14 +196,25 @@ def git_get_commit_id_from_repo_ref(repo, ref): return None logger.debug('getting commit-id from: %s %s', repo, ref) - lines = git_get_command_lines(None, ['ls-remote', repo, '%s^{}' % ref]) - if not lines: - # Try it as a head - lines = git_get_command_lines(None, ['ls-remote', repo, ref]) + # Is it a full ref name or a shortname? + if ref.find('refs/heads/') < 0 and ref.find('refs/tags/') < 0: + # Try grabbing it as a head first + lines = git_get_command_lines(None, ['ls-remote', repo, 'refs/heads/%s' % ref]) if not lines: - # Oh well, we tried - logger.debug('did not find commit-id, ignoring pull request') - return None + # try it as a tag, then + lines = git_get_command_lines(None, ['ls-remote', repo, 'refs/tags/%s^{}' % ref]) + + elif ref.find('refs/tags/') == 0: + lines = git_get_command_lines(None, ['ls-remote', repo, '%s^{}' % ref]) + + else: + # Grab it as a head and hope for the best + lines = git_get_command_lines(None, ['ls-remote', repo, ref]) + + if not lines: + # Oh well, we tried + logger.debug('did not find commit-id, ignoring pull request') + return None commit_id = lines[0].split()[0] logger.debug('success, commit-id: %s', commit_id) -- cgit 1.2.3-korg