Class: GitCli::Workspace

Inherits:
Object
  • Object
show all
Includes:
AddCommit, Branch, Common, Delta, Diff, Ignore, Log, Pull, Push, Repos, Stash, Tags, WsCommon, TR::CondUtils
Defined in:
lib/git_cli.rb

Overview

class Gvcs::Workspace

Constant Summary

Constants included from Log

Log::SIMPLE_LOG_DEFAULT_CONF

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Stash

#stash_all_changes, #stash_changes, #stash_clear, #stash_list, #stash_remove, #stash_restore, #stash_restore_and_remove, #stash_to_new_branch

Methods included from Repos

#add_remote, #remote_config, #remove_remote

Methods included from Tags

#all_tags, #checkout_tag, #create_tag, #create_tag_from_commit, #delete_remote_tag, #delete_tag, #fetch_tag_to_local, #show_tag_detail, #tag_info, #tag_points_at?

Methods included from Log

#logs, #show_log

Methods included from Ignore

#ignore, #ignore_rules, #update_ignore_rules

Methods included from Diff

#diff, #diff_branch, #diff_common, #diff_file_with_last_commit, #diff_index_with_last_commit, #diff_working_with_last_commit

Methods included from Branch

#all_branches, #create_branch, #current_branch, #delete_branch, #download_all_remote_branches_name, #local_branches, #merge_branch, #remote_branches, #switch_branch

Methods included from Pull

#pull

Methods included from Push

#push_changes, #push_changes_with_tags

Methods included from Delta

#calculate_distance, #cftFiles, #conflicted, #conflicted_files, #delFiles, #deleted, #deleted_files, #has_conflicted_file?, #has_deleted_file?, #has_modified_file?, #has_new_file?, #has_staged_file?, #is_local_ahead_of_remote?, #is_remote_ahead_of_local?, #modFiles, #modified, #modified_files, #newFiles, #new_files, #reset_all_changes, #reset_file_changes, #staged, #staged_files, #status, #stgFiles

Methods included from AddCommit

#add_to_staging, #commit, #commit_all, #remove_from_staging, #remove_from_vcs

Methods included from WsCommon

#check_vcs

Methods included from Common

#dry_run, #dry_run=, #log_debug, #log_error, #log_warn, #os_exec

Constructor Details

#initialize(path, vcs = nil) ⇒ Workspace

Returns a new instance of Workspace.



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/git_cli.rb', line 145

def initialize(path, vcs = nil)

  #raise_if_empty(vcs , "VCS cannot be empty", GitCliException)
  raise_if_empty(path, "Workspace path cannot be empty", GitCliException)

  if is_empty?(vcs)
    @vcs = GitCli::Vcs.new
  else
    @vcs = vcs
  end

  #@vcs = vcs
  @givenPath = path

  @wsPath = File.expand_path(@givenPath)

  @repos = []

end

Instance Attribute Details

#reposObject

end



240
241
242
# File 'lib/git_cli.rb', line 240

def repos
  @repos
end

Class Method Details

.args_to_string_array(*args) ⇒ Object



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/git_cli.rb', line 269

def self.args_to_string_array(*args)
  res = []
  args.each do |e|
    case e
    when Delta::VCSItem
      res << e.path
    when Array
      res.concat(args_to_string_array(*e))
    when String
      res << e
    else
      res << e.to_s
    end
  end
  res
end

Instance Method Details

#add_repos(repos) ⇒ Object



173
174
175
# File 'lib/git_cli.rb', line 173

def add_repos(repos)
  @repos << repos if not repos.nil?
end

#check_reposObject

add_repos



177
178
179
# File 'lib/git_cli.rb', line 177

def check_repos
  raise_if_empty(@repos, "Repositories should not be empty", GitCliException)
end

#has_remote_repos?Boolean

Returns:

  • (Boolean)


248
249
250
# File 'lib/git_cli.rb', line 248

def has_remote_repos?
  not_empty?(repos)
end

#is_clean?Boolean Also known as: clean?, clear?

Returns:

  • (Boolean)


252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/git_cli.rb', line 252

def is_clean?
  nd, nf = new_files
  md, mf = modified_files
  dd, df = deleted_files
  sd, sf = staged_files

  #log_debug "New Dir : #{nd}"
  #log_debug "Mod Dir : #{md}"
  #log_debug "Del Dir : #{dd}"
  #log_debug "Stg Dir : #{sd}"

  #(nd.length == 0 and nf.length == 0 and md.length == 0 and mf.length == 0 and dd.length == 0 and df.length == 0 and sd.length == 0 and sf.length == 0)
  (nf.length == 0 and mf.length == 0 and df.length == 0 and sf.length == 0)
end

#is_repos_exist?(name) ⇒ Boolean

check_repos

Returns:

  • (Boolean)


181
182
183
184
185
186
187
188
189
190
191
# File 'lib/git_cli.rb', line 181

def is_repos_exist?(name)
  found = false
  load_remote_to_repos
  @repos.each do |re|
    if re.name == name
      found = true
      break
    end
  end
  found
end

#is_workspace?Boolean

is_repos_exist?

Returns:

  • (Boolean)


193
194
195
196
197
198
199
200
201
202
203
# File 'lib/git_cli.rb', line 193

def is_workspace?
  begin
    status
    true
  rescue GitDeltaError => ex
    log_debug ex.message
    false
  end
  #st, res = status
  #st 
end

#pathObject

initialize



165
166
167
# File 'lib/git_cli.rb', line 165

def path
  @wsPath
end

#vcsObject



169
170
171
# File 'lib/git_cli.rb', line 169

def vcs
  @vcs
end

#workspace_rootObject Also known as: root_path



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/git_cli.rb', line 205

def workspace_root

  if (@wsRoot.nil? or (@wsRoot[0] == false))

    check_vcs

    cmd = []
    cmd << "cd"
    cmd << @wsPath
    cmd << "&&"
    cmd << @vcs.exe_path
    cmd << "rev-parse --show-toplevel"

    cmdln = cmd.join(" ")
    log_debug "Workspace root: #{cmdln}"
    res = os_exec(cmdln) do |st, res|

      if st.success?
        @wsRoot = res.strip
        #@wsRoot = [true, res.strip]
      else
        raise GitCliException, "Failure executing : #{cmdln} \nError was : #{res.strip}" 
        #@wsRoot = [false, res.strip]
      end
    end

  end

  @wsRoot
  
end