-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathgit-sync-all
executable file
·50 lines (42 loc) · 1.12 KB
/
git-sync-all
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
#
# git-sync-all
#
# Script for syncing the main branch with origin and rebasing all branches
# against mater.
#
# Usage:
# $ git sync-all
#
import sys
import os
import git
import util
go = util.prompt_y_n('Are you absolutely sure?')
if not go:
util.info('OK, aborting.')
exit(0)
try:
repo = git.Repo(os.getcwd(), search_parent_directories=True)
except git.exc.InvalidGitRepositoryError:
util.fatal('git sync-all must be run from within a valid git repository.')
util.fatal_if_dirty(repo)
initial_branch = repo.active_branch
util.update_main(repo, initial_branch)
had_failure = False
main = util.main_branch_name(repo)
for r in repo.branches:
if r.name != main:
util.info('Syncing %s' % r)
r.checkout()
try:
repo.git.rebase(main)
except:
repo.git.rebase('--abort')
had_failure = True
util.error('Failed to sync %s' % r)
initial_branch.checkout()
if had_failure:
util.error('Some branches failed to rebase, please try manually')
else:
util.success('%s synced with origin, and all branches rebased' % main)