From be77e273623fc8b8002c752b580ce1f3157f25ae Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Feb 08 2021 22:05:25 +0000 Subject: Better hint when running 'prep' on detached branch JIRA: RHELCMP-3682 Resolves: rhbz#1907964 Signed-off-by: Ondrej Nosek --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 52dcee3..a3f5edd 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -2874,6 +2874,24 @@ class Commands(object): # setup the rpm command cmd = ['rpmbuild'] + + # When "prep" command is run on detached branch (rhbz#1907964) + # Recreate with: "git checkout ". + # Before self.rpmdefines() executes self.load_branch_merge() and it + # shows potential confusing message to user, + # execute self.load_branch_merge() in advance and catch related + # exception. Set branch to value (=current commit id) that won't match + # any predefined branch pattern. This will lead to displaying better + # message to user (user is recommended to use --release argument) + try: + self.load_branch_merge() + except rpkgError: + head = self.repo.head + if head.is_detached: + self._branch_merge = head.commit.hexsha # current commit id + else: + raise + cmd.extend(self.rpmdefines) if builddir: # Tack on a new builddir to the end of the defines