module Autoshell::Git
Git
repo stuff @!attribute branch
@return [String] (master) branch of the current repo
Attributes
Public Instance Methods
Get a tar archive of the repo as a string
@param [String] (HEAD) Branch or tag @return [String] Zip-formatted binary string
# File lib/autoshell/git.rb, line 94 def archive(branch_or_tag = nil) git 'archive', branch_or_tag || 'HEAD', binmode: true end
# File lib/autoshell/git.rb, line 8 def branch @branch ||= 'master' end
Set the branch from a repo url
@param [String] Git
repository URL @return [string] Branch name
# File lib/autoshell/git.rb, line 17 def branch_from_repo_url(repo_url) if repo_url =~ /#\S+[^\/]/ @branch = repo_url.split('#')[1] else @branch = 'master' end end
Checkout a specific hash on the repo
@param [String] Git
version hash @return [String] Output of git commands
# File lib/autoshell/git.rb, line 77 def checkout_version(version_hash) git 'checkout', version_hash || 'HEAD' end
Clone a repo to disk from the url
@param [String] Git
repository URL @return [String] Output of git commands
# File lib/autoshell/git.rb, line 66 def clone(repo_url) mkpdir working_dir run 'git', 'clone', '--recursive', repo_url.split('#')[0], working_dir branch_from_repo_url(repo_url) update end
Get the current commit hash
@param [String] (HEAD) Branch or tag @return [String] Git
commit hash
# File lib/autoshell/git.rb, line 85 def commit_hash(branch_or_tag = nil) @version = git 'rev-parse', branch_or_tag || 'HEAD' end
# File lib/autoshell/git.rb, line 25 def commit_hash_for_checkout @commit_hash_for_checkout ||= 'HEAD' end
Run
a git command
@param [*Array<String>] Command @return [String] Command output
# File lib/autoshell/git.rb, line 102 def git(*args) cd { run(*['git'] + args) } end
Has this repo been cloned to disk?
@return [Boolean] True if this dir is a cloned repo
# File lib/autoshell/git.rb, line 33 def git? dir? '.git' end
Checkout a different branch
@param [String] Branch name @return [String] Output of git commands
# File lib/autoshell/git.rb, line 57 def switch(new_branch) self.branch = new_branch update end
Update the repo on disk
@return [String] Output of git commands
# File lib/autoshell/git.rb, line 40 def update [ git('checkout', '.'), git('clean', '-ffd'), git('fetch', 'origin'), git('checkout', branch), git('pull', '--recurse-submodules=yes'), git('checkout', commit_hash_for_checkout), git('submodule', 'update', '--init'), git('clean', '-ffd') ].join("\n") end