Module: GitCli::AddCommit

Included in:
Gvcs::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
50
# 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)

  paths = [paths] if not paths.is_a?(Array)

  cmd = []
  cmd << "cd"
  cmd << @wsPath
  cmd << "&&"
  cmd << @vcs.exe_path
  cmd << "add"
  cmd.append(paths)
  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

remove_from_vcs



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
137
# File 'lib/git_cli/add_commit.rb', line 104

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 << files.join(" ")
  end
  cmd << "-m"
  cmd << "\"#{msg}\""

  cmdln = cmd.join " "

  log_debug "Commit : #{cmdln}"

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

end

#commit_all(msg) ⇒ Object

commit



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
167
# File 'lib/git_cli/add_commit.rb', line 139

def commit_all(msg)
  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



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

def remove_from_staging(paths)
  check_vcs

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

  paths = [paths] if not paths.is_a?(Array)

  cmd = []
  cmd << "cd"
  cmd << @wsPath
  cmd << "&&"
  cmd << @vcs.exe_path
  cmd << "reset"
  cmd.append(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



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

def remove_from_vcs(paths)
  
  check_vcs

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

  paths = [paths] if not paths.is_a?(Array)

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

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

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