Module: GitCli::AddCommit

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

Defined Under Namespace

Classes: CommitError

Instance Method Summary collapse

Instance Method Details

#add_to_staging(*paths) ⇒ Object Also known as: add, add_staging



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/git_cli/add_commit.rb', line 23

def add_to_staging(*paths)
  check_vcs

  raise_if_empty(paths, "Given path to add is empty", GitCliException)

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

  cmd.append(GitCli::Workspace.args_to_string_array(paths).join(" "))
  cmdln = cmd.join " "

  log_debug "Add : #{cmdln}"

  os_exec(cmdln) do |st, res|
    res.strip!
    if not st.success?
      raise CommitError, res
    else
      res
    end
    #[st.success?, res.strip]
  end
end

#commit(message, opts = { }) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/git_cli/add_commit.rb', line 102

def commit(message, opts = { })
  check_vcs

  files = opts[:files] || []
  [files] if not files.is_a?(Array)
  # have to escape the message for command line purposes
  msg = message.gsub("\"","\\\"").gsub("\\","\\\\")

  cmd = []
  cmd << "cd"
  cmd << @wsPath
  cmd << "&&"
  cmd << @vcs.exe_path
  cmd << "commit"
  if not_empty?(files)
    cmd << GitCli::Workspace.args_to_string_array(files).join(" ")
  end
  cmd << "-m"
  cmd << "\"#{msg}\""

  cmdln = cmd.join " "

  log_debug "Commit : #{cmdln}"

  os_exec(cmdln) do |st, res|
    [st.success?, res.strip!]
    #res.strip!
    #if not st.success?
    #  raise CommitError, res
    #else
    #  res
    #end
  end

end

#commit_all(message) ⇒ Object

commit



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/git_cli/add_commit.rb', line 138

def commit_all(message)
  check_vcs
  
  # have to escape the message for command line purposes
  msg = message.gsub("\"","\\\"").gsub("\\","\\\\")

  cmd = []
  cmd << "cd"
  cmd << @wsPath
  cmd << "&&"
  cmd << @vcs.exe_path
  cmd << "commit"
  cmd << "-am"
  cmd << "\"#{msg}\""

  cmdln = cmd.join " "

  log_debug "Commit All : #{cmdln}"

  os_exec(cmdln)  do |st, res|
    res.strip!
    if not st.success?
      raise CommitError, res
    else
      res.strip
    end
  end
 
end

#remove_from_staging(*paths) ⇒ Object Also known as: remove_staging



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/git_cli/add_commit.rb', line 53

def remove_from_staging(*paths)
  check_vcs

  raise_if_empty(paths, "Given path to reset is empty", GitCliException)

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

  cmd.append(GitCli::Workspace.args_to_string_array(paths))
  cmdln = cmd.join " "

  log_debug "reset : #{cmdln}"

  os_exec(cmdln) do |st, res|
    [st.success?, res.strip]
  end
   
end

#remove_from_vcs(*paths) ⇒ Object Also known as: remove_vcs



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/git_cli/add_commit.rb', line 77

def remove_from_vcs(*paths)
  
  check_vcs

  raise_if_empty(paths, "Given path to remove from VCS is empty", GitCliException)

  cmd = []
  cmd << "cd"
  cmd << @wsPath
  cmd << "&&"
  cmd << @vcs.exe_path
  cmd << "rm --cached"
  
  cmd.append(GitCli::Workspace.args_to_string_array(paths))
  cmdln = cmd.join " "

  log_debug "Remove from git version control : #{cmdln}"

  os_exec(cmdln) do |st, res|
    [st.success?, res.strip]
  end
  
end