Class: LearnTest::Git::Wip::Base
- Inherits:
-
Git::Path
- Object
- Git::Path
- LearnTest::Git::Wip::Base
- Defined in:
- lib/learn_test/git/wip/base.rb
Constant Summary collapse
- TEMPFILE =
'.wip'
Instance Attribute Summary collapse
-
#wip_branch ⇒ Object
readonly
Returns the value of attribute wip_branch.
-
#working_branch ⇒ Object
readonly
Returns the value of attribute working_branch.
Instance Method Summary collapse
-
#initialize(base:, message:) ⇒ Base
constructor
A new instance of Base.
- #process! ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(base:, message:) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/learn_test/git/wip/base.rb', line 16 def initialize(base:, message:) @base = base @message = @success = nil current_branch = @base.current_branch raise Errors::NoCommitsError, 'master' if current_branch.nil? # TODO: Swap to `main`? @tmp = Tempfile.new(TEMPFILE) @working_branch = Branch.new(base: @base, name: current_branch) @wip_branch = Reference.new(base: @base, name: current_branch) end |
Instance Attribute Details
#wip_branch ⇒ Object (readonly)
Returns the value of attribute wip_branch.
14 15 16 |
# File 'lib/learn_test/git/wip/base.rb', line 14 def wip_branch @wip_branch end |
#working_branch ⇒ Object (readonly)
Returns the value of attribute working_branch.
14 15 16 |
# File 'lib/learn_test/git/wip/base.rb', line 14 def working_branch @working_branch end |
Instance Method Details
#process! ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/learn_test/git/wip/base.rb', line 30 def process! if @wip_branch.last_revision merge = @base.merge_base(@wip_branch.last_revision, @working_branch.last_revision) @wip_branch.parent = if merge == @working_branch.last_revision @wip_branch.last_revision else @working_branch.last_revision end else @wip_branch.parent = @working_branch.last_revision end new_tree = build_new_tree(@wip_branch.parent) @base.diff(new_tree, @wip_branch.parent) commit = @base.commit_tree(new_tree, parent: @wip_branch.parent) @base.lib.send(:command, 'update-ref', ['-m', @message, @wip_branch, commit.objectish]) @success = true ensure cleanup end |
#success? ⇒ Boolean
55 56 57 |
# File 'lib/learn_test/git/wip/base.rb', line 55 def success? @success end |