Created
December 30, 2017 01:17
-
-
Save attakei/213bb6089a26cf647d0f9080571a14fb to your computer and use it in GitHub Desktop.
Checkout all branches from 'origin'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Generated by act as 2017-12-30 09:57:20.386358 | |
""" | |
import sys | |
import logging | |
from pathlib import Path | |
from git import Repo | |
Logger = logging.getLogger('checkout_all_branches') | |
def main(argv=None): | |
Logger.debug('Start') | |
if argv is None: | |
argv = sys.argv[1:] | |
if len(argv) != 1: | |
Logger.error('Path required') | |
return 1 | |
target = Path(argv[0]).absolute() | |
for path in target.glob('*'): | |
print(path) | |
if not path.joinpath('.git').exists(): | |
Logger.info('Not git, skip') | |
continue | |
repo = Repo(str(path)) | |
origin = repo.remotes.origin | |
for remote in origin.refs: | |
if str(remote) == 'origin/HEAD': | |
continue | |
local = '/'.join(str(remote).split('/')[1:]) | |
repo.create_head(local, remote) | |
break | |
Logger.debug('End') | |
return 0 | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment