<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/repotools/+/11242">View Change</a></p><div style="white-space:pre-wrap">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

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">mkrelease.py: Be more tolerant of issues with local git repos<br><br>If mkrelease had previously failed, it's possible that an invalid<br>asterisk or testsuite git repo could be left behind.  In this case,<br>when mkrelease is run again, digium_git would detect an existing<br>directory, try to do a checkout, then fail because it's not a valid<br>git repo.<br><br>* Add a new exception "InvalidRepositoryError" to digium_git which<br>  has the local path as an attribute.  This exception is raised<br>  if a InvalidGitRepositoryError is caught from the git module.<br>  We need to capture the local path because digium_git has defaults<br>  for it and we want to give a good error message to the user.<br><br>* mkrelease now checks for the InvalidRepositoryError when getting<br>  the asterisk or testsuite repositories and if caught, asks the<br>  user if they want to blow away the existing directory and<br>  re-clone.  If mkrelease is not being run in interactive mode<br>  (unusual),  the bad directory will be blown away and re-cloned<br>  automatically.<br><br>Change-Id: I0142a5428a9005c7cb5673c808eef0994f8d14ff<br>---<br>M digium_git.py<br>M mkrelease.py<br>2 files changed, 28 insertions(+), 6 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/digium_git.py b/digium_git.py</span><br><span>index 2ad1af8..1142406 100644</span><br><span>--- a/digium_git.py</span><br><span>+++ b/digium_git.py</span><br><span>@@ -16,7 +16,7 @@</span><br><span> </span><br><span> from progressbar import ProgressBar</span><br><span> from digium_commits import DigiumCommitMessageParser</span><br><span style="color: hsl(0, 100%, 40%);">-from git import Repo, RemoteProgress</span><br><span style="color: hsl(120, 100%, 40%);">+from git import Repo, RemoteProgress, InvalidGitRepositoryError</span><br><span> from version_parser import AsteriskVersion</span><br><span> </span><br><span> LOGGER = logging.getLogger(__name__)</span><br><span>@@ -164,6 +164,9 @@</span><br><span> </span><br><span>         self.progress_bar.update(float(cur_count))</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+class InvalidRepositoryError(Exception):</span><br><span style="color: hsl(120, 100%, 40%);">+    def __init__(self, local_path):</span><br><span style="color: hsl(120, 100%, 40%);">+        self.local_path = local_path</span><br><span> </span><br><span> class DigiumGitRepo(object):</span><br><span>     """A managed Git repo</span><br><span>@@ -198,8 +201,12 @@</span><br><span> </span><br><span>         local_path = os.path.expanduser(local_path)</span><br><span>         if os.path.isdir(local_path):</span><br><span style="color: hsl(0, 100%, 40%);">-            self.repo = Repo(local_path)</span><br><span style="color: hsl(0, 100%, 40%);">-            origin = self.repo.remotes.origin</span><br><span style="color: hsl(120, 100%, 40%);">+            try:</span><br><span style="color: hsl(120, 100%, 40%);">+                self.repo = Repo(local_path)</span><br><span style="color: hsl(120, 100%, 40%);">+                origin = self.repo.remotes.origin</span><br><span style="color: hsl(120, 100%, 40%);">+            except InvalidGitRepositoryError:</span><br><span style="color: hsl(120, 100%, 40%);">+                raise InvalidRepositoryError(local_path)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>         else:</span><br><span>             if not repo_url:</span><br><span>                 raise ValueError("local_path {0} does not exist and "</span><br><span>diff --git a/mkrelease.py b/mkrelease.py</span><br><span>index a6fa655..3a0f98d 100755</span><br><span>--- a/mkrelease.py</span><br><span>+++ b/mkrelease.py</span><br><span>@@ -18,7 +18,7 @@</span><br><span> from datetime import datetime</span><br><span> from optparse import OptionParser</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-from digium_git import get_repo, delete_previous_branch</span><br><span style="color: hsl(120, 100%, 40%);">+from digium_git import get_repo, delete_previous_branch, InvalidRepositoryError</span><br><span> from version_parser import AsteriskVersion</span><br><span> from release_summary import ReleaseSummary, ReleaseSummaryOptions</span><br><span> from alembic_creator import create_db_script</span><br><span>@@ -678,8 +678,16 @@</span><br><span>     # The following are all various set up steps that extract options, prepare</span><br><span>     # the environment, and calculate what it is we are trying to create.</span><br><span>     setup_options(options)</span><br><span style="color: hsl(0, 100%, 40%);">-    repo = get_repo(options.project, options.local_root, options.remote_url,</span><br><span style="color: hsl(120, 100%, 40%);">+    try:</span><br><span style="color: hsl(120, 100%, 40%);">+        repo = get_repo(options.project, options.local_root, options.remote_url,</span><br><span>                     show_progress=options.loglevel == logging.DEBUG)</span><br><span style="color: hsl(120, 100%, 40%);">+    except InvalidRepositoryError as ire:</span><br><span style="color: hsl(120, 100%, 40%);">+        prompt_to_continue("'%s' exists but is not a valid respository.  Blow it away and re-clone?" % ire.local_path)</span><br><span style="color: hsl(120, 100%, 40%);">+        shutil.rmtree(ire.local_path, True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+        repo = get_repo(options.project, options.local_root, options.remote_url,</span><br><span style="color: hsl(120, 100%, 40%);">+                    show_progress=options.loglevel == logging.DEBUG)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>     prepare_branch(options, repo)</span><br><span>     extract_tags(options, repo)</span><br><span> </span><br><span>@@ -697,7 +705,14 @@</span><br><span> </span><br><span>     if options.project.lower() == 'asterisk':</span><br><span>         # Tags created and pushed to Asterisk remote, so update the testsuite</span><br><span style="color: hsl(0, 100%, 40%);">-        update_testsuite(version_object, options.local_root,</span><br><span style="color: hsl(120, 100%, 40%);">+        try:</span><br><span style="color: hsl(120, 100%, 40%);">+            update_testsuite(version_object, options.local_root,</span><br><span style="color: hsl(120, 100%, 40%);">+                         options.remote_url, repo)</span><br><span style="color: hsl(120, 100%, 40%);">+        except InvalidRepositoryError as ire:</span><br><span style="color: hsl(120, 100%, 40%);">+            prompt_to_continue("'%s' exists but is not a valid respository.  Blow it away and re-clone?" % ire.local_path)</span><br><span style="color: hsl(120, 100%, 40%);">+            shutil.rmtree(ire.local_path, True)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+            update_testsuite(version_object, options.local_root,</span><br><span>                          options.remote_url, repo)</span><br><span> </span><br><span>     prompt_to_continue("Proceeding to tarball.")</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/repotools/+/11242">change 11242</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/repotools/+/11242"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: repotools </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I0142a5428a9005c7cb5673c808eef0994f8d14ff </div>
<div style="display:none"> Gerrit-Change-Number: 11242 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>