Class: Cp8Cli::Branch
- Inherits:
-
Object
- Object
- Cp8Cli::Branch
- Defined in:
- lib/cp8_cli/branch.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
- #checkout ⇒ Object
-
#initialize(name) ⇒ Branch
constructor
A new instance of Branch.
- #open_ci ⇒ Object
- #open_story_in_browser ⇒ Object
- #push ⇒ Object
- #reset ⇒ Object
- #story ⇒ Object
- #target ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name) ⇒ Branch
Returns a new instance of Branch.
15 16 17 |
# File 'lib/cp8_cli/branch.rb', line 15 def initialize(name) @name = name end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/cp8_cli/branch.rb', line 13 def name @name end |
Class Method Details
.current ⇒ Object
19 20 21 |
# File 'lib/cp8_cli/branch.rb', line 19 def self.current new Command.read("git rev-parse --abbrev-ref HEAD") end |
.from_story(story) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/cp8_cli/branch.rb', line 27 def self.from_story(story) new BranchName.new( user: CurrentUser.new, target: current, title: story.title, short_link: story.short_link ).to_s end |
.suggestion ⇒ Object
23 24 25 |
# File 'lib/cp8_cli/branch.rb', line 23 def self.suggestion new("suggestion-#{SecureRandom.hex(8)}") end |
Instance Method Details
#checkout ⇒ Object
40 41 42 |
# File 'lib/cp8_cli/branch.rb', line 40 def checkout Command.run "git checkout #{name} >/dev/null 2>&1 || git checkout -b #{name}" end |
#open_ci ⇒ Object
48 49 50 |
# File 'lib/cp8_cli/branch.rb', line 48 def open_ci Ci.new(branch_name: name, repo: Repo.current).open end |
#open_story_in_browser ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/cp8_cli/branch.rb', line 52 def open_story_in_browser if story Command.open_url story.url else Command.error "Not currently on story branch" end end |
#push ⇒ Object
44 45 46 |
# File 'lib/cp8_cli/branch.rb', line 44 def push Command.run "git push origin #{name} -u" end |
#reset ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/cp8_cli/branch.rb', line 64 def reset if dirty? Command.error "Dirty working directory, not resetting." else Command.run("git reset --hard origin/#{name}") end end |
#story ⇒ Object
36 37 38 |
# File 'lib/cp8_cli/branch.rb', line 36 def story @_story ||= StoryQuery.new(short_link).find if short_link end |
#target ⇒ Object
60 61 62 |
# File 'lib/cp8_cli/branch.rb', line 60 def target name_parts[2] || "master" end |
#to_s ⇒ Object
72 73 74 |
# File 'lib/cp8_cli/branch.rb', line 72 def to_s name end |