I need to pass from the command line a list of repos and detect their default branches. So far i only found this command that returns the default HEAD git remote show origin | grep 'HEAD' | cut -d':' -f2 | sed -e 's/^ *//g' -e 's/ *$//g'
However, i'm not sure how should i execute it in my code.
Here's the execution command python3 app.py testrepo.
And below is the code
@app.route('/test')
def get_default_branch():
repos = sys.argv[1:]
origin =repos[0]
return subprocess.Popen([f"'git', 'remote', 'show', '{origin}''" + "| grep 'HEAD' | cut -d':' -f2 | sed -e 's/^ *//g' -e 's/ *$//g''" ])