[Asterisk-code-review] mkrelease.py: Be more tolerant of issues with local git repos (...repotools[master])

George Joseph asteriskteam at digium.com
Thu Apr 11 13:51:54 CDT 2019


George Joseph has submitted this change and it was merged. ( https://gerrit.asterisk.org/c/repotools/+/11242 )

Change subject: mkrelease.py: Be more tolerant of issues with local git repos
......................................................................

mkrelease.py: Be more tolerant of issues with local git repos

If mkrelease had previously failed, it's possible that an invalid
asterisk or testsuite git repo could be left behind.  In this case,
when mkrelease is run again, digium_git would detect an existing
directory, try to do a checkout, then fail because it's not a valid
git repo.

* Add a new exception "InvalidRepositoryError" to digium_git which
  has the local path as an attribute.  This exception is raised
  if a InvalidGitRepositoryError is caught from the git module.
  We need to capture the local path because digium_git has defaults
  for it and we want to give a good error message to the user.

* mkrelease now checks for the InvalidRepositoryError when getting
  the asterisk or testsuite repositories and if caught, asks the
  user if they want to blow away the existing directory and
  re-clone.  If mkrelease is not being run in interactive mode
  (unusual),  the bad directory will be blown away and re-cloned
  automatically.

Change-Id: I0142a5428a9005c7cb5673c808eef0994f8d14ff
---
M digium_git.py
M mkrelease.py
2 files changed, 28 insertions(+), 6 deletions(-)

Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/digium_git.py b/digium_git.py
index 2ad1af8..1142406 100644
--- a/digium_git.py
+++ b/digium_git.py
@@ -16,7 +16,7 @@
 
 from progressbar import ProgressBar
 from digium_commits import DigiumCommitMessageParser
-from git import Repo, RemoteProgress
+from git import Repo, RemoteProgress, InvalidGitRepositoryError
 from version_parser import AsteriskVersion
 
 LOGGER = logging.getLogger(__name__)
@@ -164,6 +164,9 @@
 
         self.progress_bar.update(float(cur_count))
 
+class InvalidRepositoryError(Exception):
+    def __init__(self, local_path):
+        self.local_path = local_path
 
 class DigiumGitRepo(object):
     """A managed Git repo
@@ -198,8 +201,12 @@
 
         local_path = os.path.expanduser(local_path)
         if os.path.isdir(local_path):
-            self.repo = Repo(local_path)
-            origin = self.repo.remotes.origin
+            try:
+                self.repo = Repo(local_path)
+                origin = self.repo.remotes.origin
+            except InvalidGitRepositoryError:
+                raise InvalidRepositoryError(local_path)
+
         else:
             if not repo_url:
                 raise ValueError("local_path {0} does not exist and "
diff --git a/mkrelease.py b/mkrelease.py
index a6fa655..3a0f98d 100755
--- a/mkrelease.py
+++ b/mkrelease.py
@@ -18,7 +18,7 @@
 from datetime import datetime
 from optparse import OptionParser
 
-from digium_git import get_repo, delete_previous_branch
+from digium_git import get_repo, delete_previous_branch, InvalidRepositoryError
 from version_parser import AsteriskVersion
 from release_summary import ReleaseSummary, ReleaseSummaryOptions
 from alembic_creator import create_db_script
@@ -678,8 +678,16 @@
     # The following are all various set up steps that extract options, prepare
     # the environment, and calculate what it is we are trying to create.
     setup_options(options)
-    repo = get_repo(options.project, options.local_root, options.remote_url,
+    try:
+        repo = get_repo(options.project, options.local_root, options.remote_url,
                     show_progress=options.loglevel == logging.DEBUG)
+    except InvalidRepositoryError as ire:
+        prompt_to_continue("'%s' exists but is not a valid respository.  Blow it away and re-clone?" % ire.local_path)
+        shutil.rmtree(ire.local_path, True)
+
+        repo = get_repo(options.project, options.local_root, options.remote_url,
+                    show_progress=options.loglevel == logging.DEBUG)
+
     prepare_branch(options, repo)
     extract_tags(options, repo)
 
@@ -697,7 +705,14 @@
 
     if options.project.lower() == 'asterisk':
         # Tags created and pushed to Asterisk remote, so update the testsuite
-        update_testsuite(version_object, options.local_root,
+        try:
+            update_testsuite(version_object, options.local_root,
+                         options.remote_url, repo)
+        except InvalidRepositoryError as ire:
+            prompt_to_continue("'%s' exists but is not a valid respository.  Blow it away and re-clone?" % ire.local_path)
+            shutil.rmtree(ire.local_path, True)
+
+            update_testsuite(version_object, options.local_root,
                          options.remote_url, repo)
 
     prompt_to_continue("Proceeding to tarball.")

-- 
To view, visit https://gerrit.asterisk.org/c/repotools/+/11242
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: repotools
Gerrit-Branch: master
Gerrit-Change-Id: I0142a5428a9005c7cb5673c808eef0994f8d14ff
Gerrit-Change-Number: 11242
Gerrit-PatchSet: 1
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190411/922da2d8/attachment-0001.html>


More information about the asterisk-code-review mailing list