Added a check to make sure that the specified branch to existed first

This commit is contained in:
Gregory Ballantine 2017-07-25 16:38:37 -04:00
parent f5d39b3b57
commit 45618a32df

View File

@ -1,5 +1,6 @@
from git import Repo from git import Repo
import os import os
import sys
class FormulaRepo(): class FormulaRepo():
@ -30,6 +31,11 @@ class FormulaRepo():
if tracking_key == 0: if tracking_key == 0:
# tracking a specific branch on the repo # tracking a specific branch on the repo
if tracking_value != False: if tracking_value != False:
# check to make sure that the given branch name actually exists first
if not tracking_value in self.repo.branches:
print('%s is not an existing branch name for %s - please fix this.' % (tracking_value, self.repo_path))
sys.exit(1)
repo_branch = self.repo.head.reference repo_branch = self.repo.head.reference
# check to make sure that the current tracked branch is, in fact, what we want # check to make sure that the current tracked branch is, in fact, what we want
if repo_branch != tracking_value: if repo_branch != tracking_value:
@ -45,7 +51,9 @@ class FormulaRepo():
print('Tracking a commit') print('Tracking a commit')
else: else:
# we shouldn't get here... # we shouldn't get here...
print('We shouldn\'t have a tracking key that is not 0, 1 or 2') print('So... somehow %s got a tracking key of %d, but that is not a valid tracking key!' % (self.repo_path, tracking_key))
sys.exit(1)
# pull any new updates for the repo # pull any new updates for the repo
def pull_updates(self): def pull_updates(self):