Module: Gitcycle::Commit

Included in:
Gitcycle
Defined in:
lib/gitcycle/commit.rb

Instance Method Summary collapse

Instance Method Details

#commit(*args) ⇒ Object Also known as: ci



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
# File 'lib/gitcycle/commit.rb', line 4

def commit(*args)
  msg = nil
  no_add = args.delete("--no-add")

  if args.empty?
    require_git && require_config

    puts "\nRetrieving branch information from gitcycle.\n".green
    branch = get('branch',
      'branch[name]' => branches(:current => true),
      'create' => 0
    )

    id = branch["lighthouse_url"].match(/tickets\/(\d+)/)[1] rescue nil

    if branch && id
      msg = "[##{id}]"
      msg += " #{branch["title"]}" if branch["title"]
    end
  end

  if no_add
    cmd = "git commit"
  else
    cmd = "git add . && git add . -u && git commit -a"
  end

  if File.exists?("#{Dir.pwd}/.git/MERGE_HEAD")
    Kernel.exec(cmd)
  elsif msg
    run(cmd + " -m #{msg.dump.gsub('`', "'")}")
    Kernel.exec("git commit --amend")
  elsif args.empty?
    Kernel.exec(cmd)
  else
    exec_git(:commit, args)
  end
end