#159 Warning if repo is an old checkout
Merged 7 years ago by cqi. Opened 7 years ago by cqi.

file modified
+25 -13
@@ -603,12 +603,6 @@ 

      def ns_module_name(self, ns_module_name):

          self._ns_module_name = ns_module_name

  

-     def _print_old_checkout_warning(self, module):

-         self.log.warning('Your git configuration does not use a namespace.')

-         self.log.warning('Consider updating your git configuration by running:')

-         self.log.warning('  git remote set-url %s %s',

-                          self.branch_remote, self._get_namespace_giturl(module))

- 

      def load_ns_module_name(self):

          """Loads a package module."""

  
@@ -619,7 +613,6 @@ 

                  if self.distgit_namespaced:

                      path_parts = [p for p in parts.path.split("/") if p]

                      if len(path_parts) == 1:

-                         self._print_old_checkout_warning(path_parts[0])

                          path_parts.insert(0, "rpms")

                      ns_module_name = "/".join(path_parts[-2:])

                  else:
@@ -1677,6 +1670,7 @@ 

          Optionally override .git setting to always rebase

  

          """

+         self.check_repo(is_dirty=False, all_pushed=False)

  

          cmd = ['git', 'pull']

          if self.quiet:
@@ -1706,6 +1700,7 @@ 

  

      def push(self, force=False):

          """Push changes to the remote repository"""

+         self.check_repo(is_dirty=False, all_pushed=False)

  

          # see if our branch is tracking anything

          try:
@@ -1757,10 +1752,7 @@ 

          # the first remote it finds.  When multiple remotes are in play

          # this needs to get smarter

  

-         # See if the repo is dirty first

-         if self.repo.is_dirty():

-             raise rpkgError('%s has uncommitted changes.  Use git status '

-                             'to see details' % self.path)

+         self.check_repo(all_pushed=False)

  

          # Get our list of branches

          (locals, remotes) = self._list_branches(fetch)
@@ -1793,10 +1785,13 @@ 

                                                                  err.stderr))

          return

  

-     def check_repo(self, is_dirty=True, all_pushed=True):

+     def check_repo(self, is_dirty=True, has_namespace=True, all_pushed=True):

          """Check various status of current repository

  

          :param bool is_dirty: Default to True. To check whether there is uncommitted changes.

+         :param bool has_namespace: Default to True. To check whether this repo

+             is checked out with namespace, e.g. rpms/, docker/. If the repo is

+             an old checkout, warn user with message how to fix it.

          :param bool all_pushed: Default to True. To check whether all changes are pushed.

          :raises rpkgError: if any unexpected status is detected. For example,

              if changes are not committed yet.
@@ -1805,6 +1800,23 @@ 

              if self.repo.is_dirty():

                  raise rpkgError('%s has uncommitted changes.  Use git status '

                                  'to see details' % self.path)

+         if has_namespace:

+             try:

+                 repo_name = self.push_url

+             except rpkgError:

+                 # Ignore error if cannot get remote push URL from this repo.

+                 # That is we just skip has_namespace check when that error

+                 # happens.

+                 pass

+             else:

+                 parts = urllib.parse.urlparse(repo_name)

+                 parts = [p for p in parts.path.split('/') if p]

+                 not_contain_namespace = len(parts) == 1

+                 if not_contain_namespace:

+                     self.log.warning('Your git configuration does not use a namespace.')

+                     self.log.warning('Consider updating your git configuration by running:')

+                     self.log.warning('  git remote set-url %s %s',

+                                      self.branch_remote, self._get_namespace_giturl(parts[0]))

          if all_pushed:

              branch = self.repo.active_branch

              try:
@@ -2033,7 +2045,7 @@ 

  

      def giturl(self):

          """Return the git url that would be used for building"""

- 

+         self.check_repo(is_dirty=False, all_pushed=False)

          url = self._get_namespace_anongiturl(self.ns_module_name) + \

              '?#%s' % self.commithash

          return url

@@ -1,8 +1,12 @@ 

+ import logging

  import os

  import shutil

  import subprocess

+ import sys

  import tempfile

  

+ from mock import patch

+ from six.moves import StringIO

  from pyrpkg.errors import rpkgError

  

  from . import CommandTestCase
@@ -72,3 +76,21 @@ 

  

      def test_repo_has_everything_pushed(self):

          self.cmd.check_repo(is_dirty=False, all_pushed=True)

+ 

+     def test_check_repo_has_namespace(self):

+ 

+         def assert_warning(push_url, expected_msg):

+             with patch('sys.stderr', new=StringIO()):

+                 with patch('pyrpkg.Commands.push_url', new=push_url):

+                     self.cmd.log.addHandler(logging.StreamHandler())

+                     self.cmd.log.setLevel(logging.WARNING)

+ 

+                     self.cmd.check_repo(is_dirty=False, all_pushed=False)

+                     output = sys.stderr.getvalue()

+                     self.assertTrue(expected_msg in output)

+ 

+         assert_warning('https://localhost/package',

+                        'Your git configuration does not use a namespace.')

+         assert_warning('https://localhost/rpms/package', '')

+         assert_warning('https://localhost/docker/package', '')

+         assert_warning('https://localhost/module/rpms/package', '')

Fix #148

Warning would be given in

  • build
  • container_build_koji
  • giturl
  • osbs_build
  • pull
  • push
  • switch_branch

Signed-off-by: Chenxiong Qi cqi@redhat.com

@sergiomb Feel free to review and have a try this patch if you'd like. :)

rebased

7 years ago

have a try this patch if you'd like. :)

can't apply it on rpkg-1.46

@sergiomb What is the top commit? I guess you may need to pull before applying this patch.

the latest version available is rpkg-1.46 , and can't apply this patch on it , to test it, I need use one devel version of rpkg ...

Looks good to me. I did not test all of the listed commands, but for the ones I did it worked nicely.

rebased

7 years ago

Pull-Request has been merged by cqi

7 years ago

Thanks ! , when we have a new release ? :smile:

Is working with new rpkg/fedpkg
Many thanks.