Class: Gvcs::Workspace

Overview

WsCommon

Constant Summary

Constants included from GitCli::Log

GitCli::Log::SIMPLE_LOG_DEFAULT_CONF

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from GitCli::Stash

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

Methods included from GitCli::Repos

#add_remote, #remote_config, #remove_remote

Methods included from GitCli::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

Methods included from GitCli::Log

#logs, #show_log

Methods included from GitCli::Ignore

#ignore, #ignore_rules, #update_ignore_rules

Methods included from GitCli::Diff

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

Methods included from GitCli::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 GitCli::Pull

#pull

Methods included from GitCli::Push

#push_changes, #push_changes_with_tags

Methods included from GitCli::Delta

#conflicted_files, #deleted_files, #modified_files, #new_files, #reset_all_changes, #reset_file_changes, #staged_files, #status

Methods included from GitCli::AddCommit

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

Methods included from GitCli::WsCommon

#check_vcs

Methods included from GitCli::Common

#log_debug, #log_error, #log_warn, #os_exec

Constructor Details

#initialize(path, vcs = nil) ⇒ Workspace

Returns a new instance of Workspace.



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/git_cli.rb', line 124

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 = Gvcs::Vcs.new
  else
    @vcs = vcs
  end

  #@vcs = vcs
  @givenPath = path

  @wsPath = File.expand_path(@givenPath)

  @repos = []

end

Instance Attribute Details

#reposObject

Returns the value of attribute repos.



123
124
125
# File 'lib/git_cli.rb', line 123

def repos
  @repos
end

Instance Method Details

#add_repos(repos) ⇒ Object



152
153
154
# File 'lib/git_cli.rb', line 152

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

#check_reposObject

add_repos



156
157
158
# File 'lib/git_cli.rb', line 156

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

#is_repos_exist?(name) ⇒ Boolean

check_repos

Returns:

  • (Boolean)


160
161
162
163
164
165
166
167
168
169
170
# File 'lib/git_cli.rb', line 160

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)


172
173
174
175
176
177
178
179
180
181
182
# File 'lib/git_cli.rb', line 172

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

#load_remote_to_reposObject

workspace_root



214
215
216
217
218
219
220
221
222
# File 'lib/git_cli.rb', line 214

def load_remote_to_repos
  conf = remote_config
  conf.each do |k,v|
    repo = Gvcs::Repository.new(k, v.values.first)
    repo.support_fetch if v.keys.include?("fetch")
    repo.support_push if v.keys.include?("push")
    add_repos(repo)
  end
end

#pathObject

initialize



144
145
146
# File 'lib/git_cli.rb', line 144

def path
  @wsPath
end

#vcsObject



148
149
150
# File 'lib/git_cli.rb', line 148

def vcs
  @vcs
end

#workspace_rootObject



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/git_cli.rb', line 184

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 = [true, res]
      else
        @wsRoot = [false, res]
      end
    end

  end

  @wsRoot
  
end