-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathgit-start
More file actions
executable file
·48 lines (39 loc) · 1.33 KB
/
git-start
File metadata and controls
executable file
·48 lines (39 loc) · 1.33 KB
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
#!/usr/bin/env python
#
# git-start
#
# Creates a new feature branch off your local main branch, rather than the
# current active branch. If an error occurs you will be reverted back to the
# original branch you were on before running the script. The branch name is
# automatically prefixed with your GitHub username.
#
# Usage:
# git start bananas
#
# Is equivalent to calling:
# git checkout main
# git pull origin main
# git checkout -b dpup/bananas
#
# TODO: Can we get any status updates while waiting for 'git pull'
# TODO: Error cases need informative error messages.
import sys
import os
import git
import util
if len(sys.argv) < 2:
util.fatal('Incorrect usage, missing branch name. Use: git start [feature]')
try:
repo = git.Repo(os.getcwd(), search_parent_directories=True)
except git.exc.InvalidGitRepositoryError:
util.fatal('git start must be run from within a valid git repository.')
new_branch_name = util.get_branch_name(sys.argv[1])
initial_branch = repo.active_branch
util.fatal_if_dirty(repo)
if new_branch_name in repo.heads:
util.fatal('A branch called "%s" already exists.' % new_branch_name)
util.update_main(repo, initial_branch)
util.info('Creating new head')
new_branch = repo.create_head(new_branch_name)
new_branch.checkout()
util.success('New feature branch created for "%s".' % new_branch_name)