Class: MultiRepo::BranchCommand
- Inherits:
-
Command
- Object
- CLAide::Command
- Command
- MultiRepo::BranchCommand
show all
- Defined in:
- lib/multirepo/commands/branch-command.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Command
#ensure_in_work_tree, #ensure_multirepo_enabled, #ensure_multirepo_tracked, #install_hooks, #multirepo_enabled_dependencies, report_error, #uninstall_hooks, #update_gitconfig
Constructor Details
Returns a new instance of BranchCommand.
20
21
22
23
24
25
|
# File 'lib/multirepo/commands/branch-command.rb', line 20
def initialize(argv)
@branch_name = argv.shift_argument
@force = argv.flag?("force")
@push = argv.flag?("push", false)
super
end
|
Class Method Details
.options ⇒ Object
12
13
14
15
16
17
18
|
# File 'lib/multirepo/commands/branch-command.rb', line 12
def self.options
[
['<branch name>', 'The name of the branch to create and checkout.'],
['[--force]', 'Force creating the branch even if there are uncommmitted changes.'],
['[--push]', 'Push the branch on creation.']
].concat(super)
end
|
Instance Method Details
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/multirepo/commands/branch-command.rb', line 63
def perform_branch(repo)
Console.log_substep("Branching '#{repo.path}' ...")
Console.log_info("Creating and checking out branch #{@branch_name} ...")
branch = repo.branch(@branch_name)
branch.create unless branch.exists?
branch.checkout
if Utils.multirepo_enabled?(repo.path)
Console.log_info("Updating and committing tracking files")
tracking_files = TrackingFiles.new(repo.path)
tracking_files.update
tracking_files.commit("[multirepo] Post-branch tracking files update")
end
return unless @push
if @force
Console.log_warning("Skipping #{@branch_name} branch push because we're force-branching")
else
Console.log_info("Pushing #{@branch_name} to origin/#{@branch_name}")
repo.branch(@branch_name).push
end
end
|
#validate! ⇒ Object
27
28
29
30
31
|
# File 'lib/multirepo/commands/branch-command.rb', line 27
def validate!
super
help! "You must specify a branch name" unless @branch_name
help! "Please provide a valid branch name" unless Git.valid_branch_name?(@branch_name)
end
|