diff --git a/README.rst b/README.rst index eceb17d..2676f2d 100644 --- a/README.rst +++ b/README.rst @@ -1,8 +1,8 @@ git-project *********** -.. image:: https://travis-ci.org/3ptscience/git-project.svg?branch=master&branch=master - :target: https://travis-ci.org/3ptscience/git-project +.. image:: https://travis-ci.org/aranzgeo/git-project.svg?branch=master&branch=master + :target: https://travis-ci.org/aranzgeo/git-project Scripts extending git for better project and sub-repository management @@ -74,4 +74,4 @@ Bugs ---- If you run into any problems with `git-project`, please make an -`issue `_ +`issue `_ diff --git a/git-project b/git-project index eb9f545..4180e48 100755 --- a/git-project +++ b/git-project @@ -119,7 +119,7 @@ else: MODE = argv[1] -if MODE not in ['init', 'save', 'load', 'status']: +if MODE not in ['init', 'save', 'load', 'status', 'retarget']: usage(1) @@ -187,6 +187,8 @@ for line in lines: subrepo_info[info[0]]['branch'] = info[1].strip() subrepo_info[info[0]]['commit'] = info[2].strip() + + # ------------------------------------------------------------------------ # init case @@ -206,6 +208,54 @@ if MODE == 'init': else: print 'repo already exists!' +elif MODE == 'retarget': + + target_changes = False + for repo in subrepos: + res = subprocess.check_output( + 'cd {dir} && git remote -v'.format(dir=repo), + shell=True, + ) + name, remote, action = next( + (line.split() for line in res.split('\n') if line and line.split()[0] == 'origin') + ) + if subrepo_info[repo]['remote'] != remote: + subrepo_info[repo]['current_remote'] = remote + target_changes = True + + if target_changes: + print 'Some repository targets have changed:' + for repo in subrepos: + if 'current_remote' in subrepo_info[repo]: + print '{repo}: {current} --> {new}'.format( + repo=repo, + current=subrepo_info[repo]['current_remote'], + new=subrepo_info[repo]['remote'], + ) + + print 'Would you like to update to the new targets? [y/n/q] ' + update = sys.stdin.read(1) + if update == 'q': + finish(0) + elif update == 'y': + for repo in subrepos: + if 'current_remote' in subrepo_info[repo]: + print '\t{}...'.format(repo) + if subprocess.call( + 'cd {} && git remote set-url origin {}'.format( + repo, + subrepo_info[repo]['remote'], + ), + shell=True, + ) != 0: + print('Something went wrong changing the remote for {}!'.format(repo)) + finish(0) + subrepo_info[repo].pop('current_remote') + print + + else: + print 'There are no repositories that need to be re-targeted' + elif MODE == 'status': print 'TO BE IMPLEMENTED'