-
Notifications
You must be signed in to change notification settings - Fork 16
/
twig-checkout-parent
executable file
·63 lines (44 loc) · 1.26 KB
/
twig-checkout-parent
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
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env ruby
require 'rubygems'
require 'twig'
def help_content
<<-HELP
twig-checkout-parent
====================
Checks out a branch's parent branch.
Synopsis
--------
twig checkout-parent [-b|--branch <branch>]
Description
-----------
Checks out the current branch's parent branch, if any, based on the current
branch's `diff-branch` property.
You can use this with `twig checkout-child` to traverse your tree of branches.
Options
-------
`-b` or `--branch`: Checks out the parent branch of the given branch, rather
than the current branch.
See also
--------
twig-checkout-child
twig-create-branch
Subcommand for Twig: <http://rondevera.github.io/twig/>
Author: Ron DeVera <http://rondevera.com>
HELP
end
args = ARGV.dup
if args.include?('--help')
puts help_content
exit
end
twig = Twig.new(:read_options => true)
target_branch = twig.target_branch
parent_branch_name = target_branch.parent_name
if parent_branch_name && !parent_branch_name.empty?
exec %{git checkout "#{parent_branch_name}"}
else
parent_property = Twig::Branch::PARENT_PROPERTY
abort %{The branch "#{target_branch}" has no known parent branch.\n} \
"To set the parent branch, run:\n\n" \
" twig diff-branch <parent branch name> -b #{target_branch}"
end