Module: GitCli::Diff

Included in:
Workspace
Defined in:
lib/git_cli/diff.rb

Instance Method Summary collapse

Instance Method Details

#diffObject



22
23
24
# File 'lib/git_cli/diff.rb', line 22

def diff
  diff_branch("","")
end

#diff_branch(b1, b2, opts = { head_to_head: true }) ⇒ Object

head_to_head = true == “git diff b1..b2” -> compare head-to-head of the given two branches



34
35
36
37
38
39
40
41
42
# File 'lib/git_cli/diff.rb', line 34

def diff_branch(b1, b2, opts = { head_to_head: true })

  if not ((b1.nil? or b1.empty?) and (b2.nil? or b2.empty?))
    diff_common({ args: "#{b1}..#{b2}", log_tag: "Diff against head of two branches" })
  else
    diff_common({ args: "", log_tag: "Diff workspace with last commit" })
  end
   
end

#diff_common(opts = { }) ⇒ Object

diff_index_with_last_commit



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/git_cli/diff.rb', line 58

def diff_common(opts = { })

  check_vcs

  cmd = []
  cmd << "cd"
  cmd << @wsPath
  cmd << "&&"
  cmd << @vcs.exe_path
  cmd << "diff"

  if not (opts[:args].nil? or opts[:args].empty?)
    cmd << opts[:args]
  end

  cmdln = cmd.join(" ")
  log_debug "#{opts[:log_tag]} : #{cmdln} "

  res = os_exec(cmdln) do |st, res|
    [st.success?, res.strip!]        
    #if st.success?
    #  [true, res.strip!]
    #else
    #  [false, res]
    #end
  end
  
end

#diff_file_with_last_commit(file) ⇒ Object Also known as: diff_file



26
27
28
29
30
# File 'lib/git_cli/diff.rb', line 26

def diff_file_with_last_commit(file)

  diff_common({ args: "#{file}", log_tag: "Diff file compare with last commit" })
  
end

#diff_index_with_last_commitObject

this show different for item already put inside ‘git add’



52
53
54
55
56
# File 'lib/git_cli/diff.rb', line 52

def diff_index_with_last_commit
 
  diff_common({ args: "--cached", log_tag: "Diff index (file added with 'git add') with last commit" }) 
  
end

#diff_working_with_last_commitObject

changes to push to repos if ‘git commit -a’ is run



45
46
47
48
49
# File 'lib/git_cli/diff.rb', line 45

def diff_working_with_last_commit

  diff_common({ args: "HEAD^ HEAD", log_tag: "Diff working with last commit" })
   
end