def strip_repo_at(path): with cd(path): origin_url = check_output(['git', 'remote', 'get-url', 'origin'], text=True).strip() if len(origin_url) == 0: raise RuntimeError('Could not find origin URL') shutil.rmtree('.git') check_call(['git', 'init']) check_call(['git', 'remote', 'add', 'origin', origin_url])
def push_dir(path, site_dict, strip=False): with cd(path): ex_name = op.basename(path) has_history = op.isdir('.git') if has_history: if strip: strip_repo_at('.') else: # No history check_call(['git', 'init']) check_call(['hub', 'create', f"{site_dict['org_name']}/{ex_name}"]) check_call(['git', 'add', '.']) if len(check_output(['git', 'diff', '--staged'])) == 0: print('No changes to commit') return check_call(['git', 'commit', '-m', 'Update from template']) check_call(['git', 'push', 'origin', 'master'] + (['--force'] if strip else []))
def push_dir(path, site_dict, strip=False): with cd(path): ex_name = op.basename(path) has_history = op.isdir('.git') if has_history: if strip: strip_repo_at('.') else: # No history check_call(['git', 'init']) check_call(['hub', 'create', f"{site_dict['org_name']}/{ex_name}"]) check_call(['git', 'add', '.']) if len(check_output(['git', 'diff', '--staged'])) == 0: print('No changes to commit') return check_call(['git', 'commit', '-m', 'Update from template']) # Check default branch. res = check_output(['git', 'rev-parse', '--abbrev-ref', 'HEAD'], text=True).strip() check_call(['git', 'push', 'origin', res] + (['--force'] if strip else []))