Skip to content

Commit

Permalink
app.py: setup remotes during startup
Browse files Browse the repository at this point in the history
  • Loading branch information
shiv-tyagi committed May 11, 2024
1 parent 32f19c7 commit f9c2a5e
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ def set_remotes(remotes):
global REMOTES
REMOTES = remotes

def fetch_remote(remote_name):
app.logger.info("Fetching remote %s" % remote_name)
run_git(['git', 'fetch', remote_name], sourcedir)

def get_git_hash(remote, commit_reference, fetch=False):
if remote is None or commit_reference is None:
return ''

# fetch remote
if fetch:
run_git(['git', 'fetch', remote], cwd=sourcedir)
fetch_remote(remote)

app.logger.info("Running git rev-parse on %s remote for %s branch in %s" % (remote, commit_reference, sourcedir))
# this returns git hash if commit_reference is a branch on given remote
Expand Down Expand Up @@ -119,7 +123,7 @@ def do_checkout(remote, commit_reference, s_dir, force_fetch=False, temp_branch_
'''checkout to given commit/branch/tag and return the git hash'''
# Note: remember to acquire head_lock before calling this method
if force_fetch:
run_git(['git', 'fetch', remote], cwd=s_dir)
fetch_remote(remote)

git_hash_target = get_git_hash(remote, commit_reference)

Expand Down Expand Up @@ -199,6 +203,30 @@ def get_build_options_from_ardupilot_tree(s_dir):
}
})

def setup_remotes():
added_remotes = 0
for remote in REMOTES:
# add new remote
result = subprocess.run(['git', 'remote', 'add', remote['name'], remote['url']], cwd=sourcedir, encoding='utf-8', capture_output=True, shell=False)

# non-zero returncode? the remote already exists probably
# To-do
# change this condition to be specific for returncode 3
# which is returned when remote already exists, this change came after git version 2.30
if result.returncode != 0:
app.logger.info("Remote %s already exists, updating url" % remote['name'])
result = subprocess.run(['git', 'remote', 'set-url', remote['name'], remote['url']], cwd=sourcedir, encoding='utf-8', capture_output=True, shell=False)

# did we succeed?
if result.returncode != 0:
app.logger.error("Failed to add/update remote %s %s %s" % (remote['name'], remote['url'], result.stderr.rstrip()))
else:
app.logger.info("Initial fetch")
fetch_remote(remote['name'])
added_remotes += 1

app.logger.info("%d/%d remotes added" % (added_remotes, len(REMOTES)))

def remove_directory_recursive(dirname):
'''remove a directory recursively'''
app.logger.info('Removing directory ' + dirname)
Expand Down Expand Up @@ -505,10 +533,7 @@ def update_submodules(s_dir):
app.logger.info("No queue lock")

load_remotes()
app.logger.info('Initial fetch')
# checkout to default branch, fetch remote, update submodules
do_checkout("upstream", "master", s_dir=sourcedir, force_fetch=True)
update_submodules(s_dir=sourcedir)
setup_remotes()

app.logger.info('Python version is: %s' % sys.version)

Expand Down

0 comments on commit f9c2a5e

Please sign in to comment.