Class: GitProc::GitLib

Inherits:
Object
  • Object
show all
Defined in:
lib/git-process/git_lib.rb

Overview

Provides Git commands

noinspection RubyTooManyMethodsInspection

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, logging_opts) ⇒ GitLib

Returns a new instance of GitLib.

Parameters:

  • dir (Dir)

    the work dir

  • logging_opts (Hash)

    see log_level



35
36
37
38
# File 'lib/git-process/git_lib.rb', line 35

def initialize(dir, logging_opts)
  self.log_level = GitLib.log_level(logging_opts)
  self.workdir = dir
end

Class Method Details

.find_workdir(dir) ⇒ Object



111
112
113
114
115
116
117
118
119
# File 'lib/git-process/git_lib.rb', line 111

def self.find_workdir(dir)
  if dir == File::SEPARATOR
    return nil
  elsif File.directory?(File.join(dir, '.git'))
    return dir
  else
    return find_workdir(File.expand_path("#{dir}#{File::SEPARATOR}.."))
  end
end

.log_level(opts) ⇒ Fixnum

Decodes the [Hash] to determine what logging level to use

Parameters:

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :log_level (Fixnum)

    the log level from Logger

  • :quiet (Logger::ERROR)
  • :verbose (Logger::DEBUG)

Returns:

  • (Fixnum)

    the log level from Logger; defaults to Logger::INFO



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/git-process/git_lib.rb', line 59

def self.log_level(opts)
  if opts[:log_level]
    return opts[:log_level]
  elsif opts[:quiet]
    return Logger::ERROR
  elsif opts[:verbose]
    return Logger::DEBUG
  else
    return Logger::INFO
  end
end

Instance Method Details

#add(file) ⇒ String

‘git add`

Parameters:

  • file (String)

    the name of the file to add to the index

Returns:

  • (String)

    the output of ‘git add’



252
253
254
255
# File 'lib/git-process/git_lib.rb', line 252

def add(file)
  logger.info { "Adding #{[*file].join(', ')}" }
  return command(:add, ['--', file])
end

#branch(branch_name, opts = {}) ⇒ String

Does branch manipulation.

Parameters:

  • branch_name (String)

    the name of the branch

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :delete (Boolean)

    delete the remote branch

  • :force (Boolean)

    force the update

  • :all (Boolean)

    list all branches, local and remote

  • :no_color (Boolean)

    force not using any ANSI color codes

  • :rename (String)

    the new name for the branch

  • :upstream (String)

    the new branch to track

  • :base_branch (String) — default: 'master'

    the branch to base the new branch off of

Returns:

  • (String)

    the output of running the git command



382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
# File 'lib/git-process/git_lib.rb', line 382

def branch(branch_name, opts = {})
  if branch_name
    if opts[:delete]
      return delete_branch(branch_name, opts[:force])
    elsif opts[:rename]
      return rename_branch(branch_name, opts[:rename])
    elsif opts[:upstream]
      return set_upstream_branch(branch_name, opts[:upstream])
    else
      base_branch = opts[:base_branch] || 'master'
      if opts[:force]
        return change_branch(branch_name, base_branch)
      else
        return create_branch(branch_name, base_branch)
      end
    end
  else
    #list_branches(opts)
    return list_branches(opts[:all], opts[:remote], opts[:no_color])
  end
end

#branchesGitBranches

Returns:



357
358
359
# File 'lib/git-process/git_lib.rb', line 357

def branches
  GitProc::GitBranches.new(self)
end

#checkout(branch_name, opts = {}) ⇒ void

This method returns an undefined value.

Parameters:

  • branch_name (String)

    the name of the branch to checkout/create

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :no_track (Boolean)

    do not track the base branch

  • :new_branch (String)

    the name of the base branch



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# File 'lib/git-process/git_lib.rb', line 537

def checkout(branch_name, opts = {})
  args = []
  args << '--no-track' if opts[:no_track]
  args << '-b' if opts[:new_branch]
  args << branch_name
  args << opts[:new_branch] if opts[:new_branch]
  branches = branches()
  command(:checkout, args)

  branches << GitBranch.new(branch_name, opts[:new_branch] != nil, self)

  if block_given?
    yield
    command(:checkout, branches.current.name)
    branches.current
  else
    branches[branch_name]
  end
end

#command(cmd, opts = [], chdir = true, redirect = '') { ... } ⇒ String

Executes the given git command

Parameters:

  • cmd (Symbol, String)

    the command to run (e.g., :commit)

  • opts (Array<String, Symbol>) (defaults to: [])

    the arguments to pass to the command

  • chdir (Boolean) (defaults to: true)

    should the shell change to the top of the working dir before executing the command?

  • redirect (String) (defaults to: '')

    ???????

Yields:

  • the block to run in the context of running the command

Returns:

  • (String)

    the output of the git command



646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# File 'lib/git-process/git_lib.rb', line 646

def command(cmd, opts = [], chdir = true, redirect = '', &block)
  ENV['GIT_INDEX_FILE'] = File.join(workdir, '.git', 'index')
  ENV['GIT_DIR'] = File.join(workdir, '.git')
  ENV['GIT_WORK_TREE'] = workdir
  path = workdir

  git_cmd = create_git_command(cmd, opts, redirect)

  out = command_git_cmd(path, git_cmd, chdir, block)

  if logger
    logger.debug(git_cmd)
    logger.debug(out)
  end

  handle_exitstatus($?, git_cmd, out)
end

#commit(msg = nil) ⇒ String

‘git commit`

Parameters:

  • msg (String) (defaults to: nil)

    the commit message

Returns:

  • (String)

    the output of ‘git commit’



263
264
265
266
# File 'lib/git-process/git_lib.rb', line 263

def commit(msg = nil)
  logger.info 'Committing changes'
  return command(:commit, msg.nil? ? nil : ['-m', msg])
end

#configGitConfig

Returns the git configuration.

Returns:



224
225
226
227
228
229
# File 'lib/git-process/git_lib.rb', line 224

def config
  if @config.nil?
    @config = GitConfig.new(self)
  end
  return @config
end

#delete_sync_control_file!(branch_name) ⇒ void

This method returns an undefined value.

Delete the sync control file for the branch



700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
# File 'lib/git-process/git_lib.rb', line 700

def delete_sync_control_file!(branch_name)
  filename = sync_control_filename(branch_name)
  logger.debug { "Deleting sync control file, #{filename}" }

  # on some systems, especially Windows, the file may be locked. wait for it to unlock
  counter = 10
  while counter > 0
    begin
      File.delete(filename)
      counter = 0
    rescue
      counter = counter - 1
      sleep(0.25)
    end
  end
end

#fetch(name = remote.name) ⇒ String

‘git fetch`

Returns:

  • (String)

    the output of ‘git fetch’



311
312
313
314
315
316
317
318
# File 'lib/git-process/git_lib.rb', line 311

def fetch(name = remote.name)
  logger.info 'Fetching the latest changes from the server'
  output = self.command(:fetch, ['-p', name])

  log_fetch_changes(fetch_changes(output))

  return output
end

#fetch_changes(output) ⇒ Hash

Returns with lists for each of :new_branch, :new_tag, :force_updated, :deleted, :updated.

Returns:

  • (Hash)

    with lists for each of :new_branch, :new_tag, :force_updated, :deleted, :updated



322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# File 'lib/git-process/git_lib.rb', line 322

def fetch_changes(output)
  changed = output.split("\n")

  changes = {:new_branch => [], :new_tag => [], :force_updated => [], :deleted => [], :updated => []}

  line = changed.shift

  until line.nil? do
    case line
      when /^\s\s\s/
        m = /^\s\s\s(\S+)\s+(\S+)\s/.match(line)
        changes[:updated] << "#{m[2]} (#{m[1]})"
      when /^\s\*\s\[new branch\]/
        m = /^\s\*\s\[new branch\]\s+(\S+)\s/.match(line)
        changes[:new_branch] << m[1]
      when /^\s\*\s\[new tag\]/
        m = /^\s\*\s\[new tag\]\s+(\S+)\s/.match(line)
        changes[:new_tag] << m[1]
      when /^\sx\s/
        m = /^\sx\s\[deleted\]\s+\(none\)\s+->\s+[^\/]+\/(\S+)/.match(line)
        changes[:deleted] << m[1]
      when /^\s\+\s/
        m = /^\s\+\s(\S+)\s+(\S+)\s/.match(line)
        changes[:force_updated] << "#{m[2]} (#{m[1]})"
      else
        # ignore the line
    end
    line = changed.shift
  end

  changes
end

#fetch_remote_changes(remote_name = nil) ⇒ void

This method returns an undefined value.



123
124
125
126
127
128
129
# File 'lib/git-process/git_lib.rb', line 123

def fetch_remote_changes(remote_name = nil)
  if remote.exists?
    fetch(remote_name || remote.name)
  else
    logger.debug 'Can not fetch latest changes because there is no remote defined'
  end
end

#has_a_remote?Boolean

Returns does this have a remote defined?.

Returns:

  • (Boolean)

    does this have a remote defined?



242
243
244
# File 'lib/git-process/git_lib.rb', line 242

def has_a_remote?
  remote.exists?
end

#is_parked?Boolean

Returns is the current branch the “parked” branch?.

Returns:

  • (Boolean)

    is the current branch the “parked” branch?



189
190
191
192
# File 'lib/git-process/git_lib.rb', line 189

def is_parked?
  mybranches = self.branches()
  return mybranches.parking == mybranches.current
end

#log_countint

Returns the number of commits that exist in the current branch.

Returns:

  • (int)

    the number of commits that exist in the current branch



559
560
561
# File 'lib/git-process/git_lib.rb', line 559

def log_count
  command(:log, '--oneline').split(/\n/).length
end

#log_levelFixnum

Returns the logging level to use; defaults to Logger::WARN.

Returns:

  • (Fixnum)

    the logging level to use; defaults to Logger::WARN



73
74
75
# File 'lib/git-process/git_lib.rb', line 73

def log_level
  @log_level || Logger::WARN
end

#log_level=(lvl) ⇒ void

This method returns an undefined value.

Parameters:

  • lvl (Fixnum)

    the logging level to use. See Logger



80
81
82
# File 'lib/git-process/git_lib.rb', line 80

def log_level=(lvl)
  @log_level = lvl
end

#loggerGitLogger

Returns the logger to use.

Returns:



42
43
44
45
46
47
# File 'lib/git-process/git_lib.rb', line 42

def logger
  if @logger.nil?
    @logger = GitLogger.new(log_level)
  end
  return @logger
end

#merge(base, opts = {}) ⇒ String

‘git merge`

Returns:

  • (String)

    the output of ‘git merge’



298
299
300
301
302
303
304
# File 'lib/git-process/git_lib.rb', line 298

def merge(base, opts= {})
  logger.info { "Merging #{branches.current.name} with #{base}" }
  args = []
  args << '-s' << opts[:merge_strategy] if opts[:merge_strategy]
  args << base
  return command(:merge, args)
end

#porcelain_statusString

Returns the raw porcelain status string.

Returns:

  • (String)

    the raw porcelain status string



589
590
591
# File 'lib/git-process/git_lib.rb', line 589

def porcelain_status
  command(:status, '--porcelain')
end

#previous_remote_sha(current_branch, remote_branch) ⇒ String?

Returns the previous remote sha ONLY IF it is not the same as the new remote sha; otherwise nil.

Returns:

  • (String, nil)

    the previous remote sha ONLY IF it is not the same as the new remote sha; otherwise nil



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/git-process/git_lib.rb', line 163

def previous_remote_sha(current_branch, remote_branch)
  return nil unless has_a_remote?
  return nil unless remote_branches.include?(remote_branch)

  control_file_sha = read_sync_control_file(current_branch)
  old_sha = control_file_sha || remote_branch_sha(remote_branch)
  fetch_remote_changes
  new_sha = remote_branch_sha(remote_branch)

  if old_sha != new_sha
    logger.info('The remote branch has changed since the last time')
    return old_sha
  else
    logger.debug 'The remote branch has not changed since the last time'
    return nil
  end
end

#proc_merge(base, opts = {}) ⇒ Object

Executes a merge, but translates any GitProc::GitExecuteError to a MergeError

Raises:

  • (MergeError)

    if there is a problem executing the merge



153
154
155
156
157
158
159
# File 'lib/git-process/git_lib.rb', line 153

def proc_merge(base, opts = {})
  begin
    return merge(base, opts)
  rescue GitExecuteError => merge_error
    raise MergeError.new(merge_error.message, self)
  end
end

#proc_rebase(base, opts = {}) ⇒ Object

Executes a rebase, but translates any GitProc::GitExecuteError to a RebaseError

Parameters:

  • upstream (String)

    the commit-ish to rebase against

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :interactive (Object)

    do an interactive rebase

  • :oldbase (String)

    the old base to rebase from

Raises:

  • (RebaseError)

    if there is a problem executing the rebase



138
139
140
141
142
143
144
# File 'lib/git-process/git_lib.rb', line 138

def proc_rebase(base, opts = {})
  begin
    return rebase(base, opts)
  rescue GitExecuteError => rebase_error
    raise RebaseError.new(rebase_error.message, self)
  end
end

#push(remote_name, local_branch, remote_branch, opts = {}) ⇒ String

Pushes the given branch to the server.

Parameters:

  • remote_name (String)

    the repository name; nil -> ‘origin’

  • local_branch (String)

    the local branch to push; nil -> the current branch

  • remote_branch (String)

    the name of the branch to push to; nil -> same as local_branch

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :delete (Boolean, String)

    delete the remote branch

  • :force (Boolean)

    force the update, even if not a fast-forward?

Returns:

  • (String)

    the output of the push command

Raises:

  • (ArgumentError)

    if :delete is true, but no branch name is given



419
420
421
422
423
424
425
# File 'lib/git-process/git_lib.rb', line 419

def push(remote_name, local_branch, remote_branch, opts = {})
  if opts[:delete]
    return push_delete(remote_branch || local_branch, remote_name, opts)
  else
    return push_to_remote(local_branch, remote_branch, remote_name, opts)
  end
end

#push_delete(branch_name, remote_name, opts) ⇒ String

TODO:

remove the opts param

Pushes the given branch to the server.

Parameters:

  • remote_name (String)

    the repository name; nil -> ‘origin’

  • branch_name (String)

    the name of the branch to push to

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :delete (Boolean, String)

    if a String it is the branch name

Returns:

  • (String)

    the output of the push command

Raises:

  • (ArgumentError)

    no branch name is given

  • (raise GitProc::GitProcessError)

    trying to delete the integration branch



476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/git-process/git_lib.rb', line 476

def push_delete(branch_name, remote_name, opts)
  remote_name ||= 'origin'

  args = [remote_name]

  if branch_name
    rb = branch_name
  elsif !(opts[:delete].is_a? TrueClass)
    rb = opts[:delete]
  else
    raise ArgumentError.new('Need a branch name to delete.')
  end

  int_branch = config.master_branch
  if rb == int_branch
    raise GitProc::GitProcessError.new("Can not delete the integration branch '#{int_branch}'")
  end

  logger.info { "Deleting remote branch '#{rb}' on '#{remote_name}'." }
  args << '--delete' << rb
  return command(:push, args)
end

#push_to_remote(local_branch, remote_branch, remote_name, opts) ⇒ String

Pushes the given branch to the server.

Parameters:

  • remote_name (String)

    the repository name; nil -> ‘origin’

  • local_branch (String)

    the local branch to push; nil -> the current branch

  • remote_branch (String)

    the name of the branch to push to; nil -> same as local_branch

  • opts (Hash)

    a customizable set of options

Options Hash (opts):

  • :force (Boolean)

    force the update, even if not a fast-forward?

Returns:

  • (String)

    the output of the push command



439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/git-process/git_lib.rb', line 439

def push_to_remote(local_branch, remote_branch, remote_name, opts)
  remote_name ||= 'origin'

  args = [remote_name]

  local_branch ||= branches.current
  remote_branch ||= local_branch
  args << '-f' if opts[:force]

  logger.info do
    if local_branch == remote_branch
      "Pushing to '#{remote_branch}' on '#{remote_name}'."
    else
      "Pushing #{local_branch} to '#{remote_branch}' on '#{remote_name}'."
    end
  end

  args << "#{local_branch}:#{remote_branch}"
  return command(:push, args)
end

#push_to_server(local_branch, remote_branch, opts = {}) ⇒ void

This method returns an undefined value.

Push the repository to the server.

Parameters:

  • local_branch (String)

    the name of the local branch to push from

  • remote_branch (String)

    the name of the remote branch to push to

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :local (Boolean)

    should this do nothing because it is in local-only mode?

  • :force (Boolean)

    should it force the push even if it can not fast-forward?

  • :prepush (Proc)

    a block to call before doing the push

  • :postpush (Proc)

    a block to call after doing the push



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/git-process/git_lib.rb', line 206

def push_to_server(local_branch, remote_branch, opts = {})
  if opts[:local]
    logger.debug('Not pushing to the server because the user selected local-only.')
  elsif not has_a_remote?
    logger.debug('Not pushing to the server because there is no remote.')
  elsif local_branch == config.master_branch
    logger.warn('Not pushing to the server because the current branch is the mainline branch.')
  else
    opts[:prepush].call if opts[:prepush]

    push(remote.name, local_branch, remote_branch, :force => opts[:force])

    opts[:postpush].call if opts[:postpush]
  end
end

#read_sync_control_file(branch_name) ⇒ String?

Returns the SHA-1 of the latest sync performed for the branch, or nil if none is recorded.

Returns:

  • (String, nil)

    the SHA-1 of the latest sync performed for the branch, or nil if none is recorded

See Also:



680
681
682
683
684
685
686
687
688
689
690
691
692
# File 'lib/git-process/git_lib.rb', line 680

def read_sync_control_file(branch_name)
  filename = sync_control_filename(branch_name)
  if File.exists?(filename)
    sha = File.open(filename) do |file|
      file.readline.chop
    end
    logger.debug "Read sync control file, #{filename}: #{sha}"
    sha
  else
    logger.debug "Sync control file, #{filename}, was not found"
    nil
  end
end

#rebase(upstream, opts = {}) ⇒ String

‘git rebase`

Parameters:

  • upstream (String)

    the commit-ish to rebase against

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :interactive (Object)

    do an interactive rebase

  • :oldbase (String)

    the old base to rebase from

Returns:

  • (String)

    the output of ‘git rebase’



277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/git-process/git_lib.rb', line 277

def rebase(upstream, opts = {})
  args = []
  if opts[:interactive]
    logger.info { "Interactively rebasing #{branches.current.name} against #{upstream}" }
    args << '-i'
    args << upstream
  elsif opts[:oldbase]
    logger.info { "Doing rebase from #{opts[:oldbase]} against #{upstream} on #{branches.current.name}" }
    args << '--onto' << upstream << opts[:oldbase] << branches.current.name
  else
    logger.info { "Rebasing #{branches.current.name} against #{upstream}" }
    args << upstream
  end
  return command('rebase', args)
end

#rebase_continueString

‘git rebase –continue`

Returns:

  • (String)

    the output of the git command



503
504
505
# File 'lib/git-process/git_lib.rb', line 503

def rebase_continue
  command(:rebase, '--continue')
end

#remoteGitRemote

Returns the git remote configuration.

Returns:

  • (GitRemote)

    the git remote configuration



233
234
235
236
237
238
# File 'lib/git-process/git_lib.rb', line 233

def remote
  if @remote.nil?
    @remote = GitProc::GitRemote.new(config)
  end
  return @remote
end

#remote_branch_sha(remote_branch) ⇒ Object



182
183
184
185
# File 'lib/git-process/git_lib.rb', line 182

def remote_branch_sha(remote_branch)
  logger.debug { "getting sha for remotes/#{remote_branch}" }
  return rev_parse("remotes/#{remote_branch}") rescue ''
end

#remote_branchesGitBranches

Returns:



363
364
365
# File 'lib/git-process/git_lib.rb', line 363

def remote_branches
  GitProc::GitBranches.new(self, :remote => true)
end

#remove(files, opts = {}) ⇒ String

Remove the files from the Index

Parameters:

  • files (Array<String>)

    the file names to remove from the Index

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :force (Object)

    if exists and not false, will force the removal of the files

Returns:

  • (String)

    the output of the git command



571
572
573
574
575
576
# File 'lib/git-process/git_lib.rb', line 571

def remove(files, opts = {})
  args = []
  args << '-f' if opts[:force]
  args << [*files]
  command(:rm, args)
end

#reset(rev_name, opts = {}) ⇒ Object

Resets the Index/Working Directory to the given revision

Parameters:

  • rev_name (String)

    the revision name (commit-ish) to go back to

  • opts (Hash) (defaults to: {})

    a customizable set of options

Options Hash (opts):

  • :hard (Object)

    should the working directory be changed? If false or missing, will only update the Index



601
602
603
604
605
606
607
608
609
# File 'lib/git-process/git_lib.rb', line 601

def reset(rev_name, opts = {})
  args = []
  args << '--hard' if opts[:hard]
  args << rev_name

  logger.info { "Resetting #{opts[:hard] ? '(hard)' : ''} to #{rev_name}" }

  command(:reset, args)
end

#rev_list(start_revision, end_revision, opts = {}) ⇒ Object



612
613
614
615
616
617
618
# File 'lib/git-process/git_lib.rb', line 612

def rev_list(start_revision, end_revision, opts ={})
  args = []
  args << "-#{opts[:num_revs]}" if opts[:num_revs]
  args << '--oneline' if opts[:oneline]
  args << "#{start_revision}..#{end_revision}"
  command('rev-list', args)
end

#rev_parse(name) ⇒ String? Also known as: sha

Translate the commit-ish name to the SHA-1 hash value

Returns:

  • (String, nil)

    the SHA-1 value, or nil if the revision name is unknown



626
627
628
629
# File 'lib/git-process/git_lib.rb', line 626

def rev_parse(name)
  sha = command('rev-parse', ['--revs-only', name])
  return sha.empty? ? nil : sha
end

#set_upstream_branch(branch_name, upstream) ⇒ Object



726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
# File 'lib/git-process/git_lib.rb', line 726

def set_upstream_branch(branch_name, upstream)
  logger.info { "Setting upstream/tracking for branch '#{branch_name}' to '#{upstream}'." }

  if has_a_remote?
    parts = upstream.split(/\//)
    if parts.length() > 1
      potential_remote = parts.shift
      if remote.remote_names.include?(potential_remote)
        config["branch.#{branch_name}.remote"] = potential_remote
        config["branch.#{branch_name}.merge"] = "refs/heads/#{parts.join('/')}"
      end
    else
      config["branch.#{branch_name}.merge"] = "refs/heads/#{upstream}"
    end
  else
    config["branch.#{branch_name}.merge"] = "refs/heads/#{upstream}"
  end

  # The preferred way assuming using git 1.8 cli
  #command(:branch, ['--set-upstream-to', upstream, branch_name])
end

#show(refspec) ⇒ String

‘git show`

Returns:

  • (String)

    the output of the git command



527
528
529
# File 'lib/git-process/git_lib.rb', line 527

def show(refspec)
  command(:show, refspec)
end

#stash_popString

‘git stash –pop`

Returns:

  • (String)

    the output of the git command



519
520
521
# File 'lib/git-process/git_lib.rb', line 519

def stash_pop
  command(:stash, %w(pop))
end

#stash_saveString

‘git stash –save`

Returns:

  • (String)

    the output of the git command



511
512
513
# File 'lib/git-process/git_lib.rb', line 511

def stash_save
  command(:stash, %w(save))
end

#statusStatus

Returns the status of the git repository.

Returns:

  • (Status)


583
584
585
# File 'lib/git-process/git_lib.rb', line 583

def status
  GitStatus.new(self)
end

#sync_control_file_exists?(branch_name) ⇒ Boolean

Returns does the sync control file exist?.

Returns:

  • (Boolean)

    does the sync control file exist?

See Also:



720
721
722
723
# File 'lib/git-process/git_lib.rb', line 720

def sync_control_file_exists?(branch_name)
  filename = sync_control_filename(branch_name)
  File.exist?(filename)
end

#workdirDir

Returns the working directory.

Returns:

  • (Dir)

    the working directory



86
87
88
# File 'lib/git-process/git_lib.rb', line 86

def workdir
  @workdir
end

#workdir=(dir) ⇒ void

This method returns an undefined value.

Sets the working directory to use for the (non-bare) repository.

If the directory is not part of an existing repository, a new repository is created. (i.e., “git init”)

Parameters:

  • dir (Dir)

    the working directory



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/git-process/git_lib.rb', line 98

def workdir=(dir)
  workdir = GitLib.find_workdir(dir)
  if workdir.nil?
    @workdir = dir
    logger.info { "Initializing new repository at #{dir}" }
    return command(:init)
  else
    @workdir = workdir
    logger.debug { "Opening existing repository at #{dir}" }
  end
end

#write_sync_control_file(branch_name) ⇒ void

This method returns an undefined value.

Writes the current SHA-1 for the tip of the branch to the “sync control file”



670
671
672
673
674
675
# File 'lib/git-process/git_lib.rb', line 670

def write_sync_control_file(branch_name)
  latest_sha = rev_parse(branch_name)
  filename = sync_control_filename(branch_name)
  logger.debug { "Writing sync control file, #{filename}, with #{latest_sha}" }
  File.open(filename, 'w') { |f| f.puts latest_sha }
end