Added tracking of a specific git branch; added pulling for new repo updates

This commit is contained in:
Gregory Ballantine 2017-07-25 10:43:44 -04:00
parent 4aa1141538
commit 3c05c1a9d9
3 changed files with 46 additions and 2 deletions

View File

@ -40,9 +40,20 @@ class Formula():
local_path = str(self.formulas_dir) + '/' + str(self.formula_def) + '-formula'
else:
# entry type is not supported
print('One of your formula entries is not a dict or a string (' + str(formula_def) + ') - please fix this.')
print('One of your formula entries is not a dict or a string (' + str(self.formula_def) + ') - please fix this.')
sys.exit(1)
# set the class values here
self.git_url = git_url
self.local_path = local_path
# checks to see if a branch, tag, or commit to track has been defined
def get_tracking_state(self):
if 'track_branch' in self.formula_def:
return 0, self.formula_def['track_branch']
elif 'track_tag' in self.formula_def:
return 1, self.formula_def['track_tag']
elif 'track_commit' in self.formula_def:
return 2, self.formula_def['track_commit']
else:
return 0, False

View File

@ -24,3 +24,31 @@ class FormulaRepo():
# let the user know it's already downloaded so we'll update it later
print(self.repo_path + ' already exists, so we\'re not downloading it again.')
self.repo = Repo(self.repo_path)
# check if the repo is up to date
def check_tracking_info(self, tracking_key, tracking_value):
if tracking_key == 0:
# tracking a specific branch on the repo
if tracking_value != False:
repo_branch = self.repo.head.reference
# check to make sure that the current tracked branch is, in fact, what we want
if repo_branch != tracking_value:
self.repo.head.reference = repo_branch
# let the user know which branch we're using
print('For %s, we\'re using the %s branch.' % (self.repo_path, self.repo.head.reference))
elif tracking_key == 1:
# tracking a specific tag on the repo
print('Tracking a tag')
elif tracking_key == 2:
# tracking a specific commit on the repo
print('Tracking a commit')
else:
# we shouldn't get here...
print('We shouldn\'t have a tracking key that is not 0, 1 or 2')
# pull any new updates for the repo
def pull_updates(self):
print('Pulling updates for %s.' % self.repo_path)
# git pull
self.repo.remotes.origin.pull()

View File

@ -44,8 +44,13 @@ def get_formulas(formulas, formulas_dir, formulas_url):
# retrieve our formula
formula_repo.retrieve()
# get the repo tracking information from the formula definition
tracking_key, tracking_value = formula.get_tracking_state()
# make sure our formula's repo is up-to-date with the latest tracked version
## TODO
formula_repo.check_tracking_info(tracking_key, tracking_value)
# pull any new commits for the repo
formula_repo.pull_updates()
# purge un-managed formulas
def clean_formulas(conf):