Class: GitPrettyAccept::Transaction

Inherits:
Object
  • Object
show all
Includes:
Methadone::CLILogging
Defined in:
lib/git_pretty_accept/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(branch, options = {}) ⇒ Transaction

Returns a new instance of Transaction.



7
8
9
10
11
# File 'lib/git_pretty_accept/transaction.rb', line 7

def initialize(branch, options = {})
  @branch = branch
  @let_user_edit_message = options[:edit]
  @enable_autosquash = options[:autosquash]
end

Instance Attribute Details

#branchObject (readonly)

Returns the value of attribute branch.



5
6
7
# File 'lib/git_pretty_accept/transaction.rb', line 5

def branch
  @branch
end

#enable_autosquashObject (readonly)

Returns the value of attribute enable_autosquash.



5
6
7
# File 'lib/git_pretty_accept/transaction.rb', line 5

def enable_autosquash
  @enable_autosquash
end

#let_user_edit_messageObject (readonly)

Returns the value of attribute let_user_edit_message.



5
6
7
# File 'lib/git_pretty_accept/transaction.rb', line 5

def let_user_edit_message
  @let_user_edit_message
end

Instance Method Details

#callObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/git_pretty_accept/transaction.rb', line 31

def call
  commands.each_with_index do |command, i|
    info "\n#{command}"
    unless system(command)
      error "\nDue to the error above, " +
        "the following commands were not executed: " +
        commands[i + 1, commands.size].join("\n")
      exit!
    end
  end
end

#commandsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/git_pretty_accept/transaction.rb', line 13

def commands
  [
    "git fetch origin",
    "git rebase origin/#{source_branch}",
    "echo 'Confirming that #{source_branch} is not ahead of origin/#{source_branch}...'",
    "test `git rev-parse HEAD` = `git rev-parse origin/#{source_branch}`",
    "git checkout #{branch}",
    "git rebase origin/#{branch}",
    "git rebase origin/#{source_branch} #{autosquash_params}",
    "git push --force origin #{branch}",
    "git checkout #{source_branch}",
    MergeCommand.new(branch, let_user_edit_message).to_s,
    "git push origin #{source_branch}",
    "git branch -d #{branch}",
    "git push origin :#{branch}"
  ]
end

#source_branchObject



43
44
45
46
47
# File 'lib/git_pretty_accept/transaction.rb', line 43

def source_branch
  return @source_branch if @source_branch
  our = Git.open('.')
  @source_branch = our.branches.find(&:current).to_s
end