class Gitti::Git
Public Class Methods
add( *pathspecs )
click to toggle source
# File lib/gitti/git.rb, line 118 def self.add( *pathspecs ) ## e.g. git add . or git add *.rb or such cmd = 'git add' pathspecs = ['.'] if pathspecs.size == 0 cmd << " #{pathspecs.join('')}" Shell.run( cmd ) end
add_all()
click to toggle source
# File lib/gitti/git.rb, line 125 def self.add_all cmd = 'git add --all' Shell.run( cmd ) end
branch()
click to toggle source
# File lib/gitti/git.rb, line 191 def self.branch cmd = 'git branch' Shell.run( cmd ) end
changes()
click to toggle source
# File lib/gitti/git.rb, line 73 def self.changes ## same as git status --short - keep shortcut / alias - why? why not? ## returns changed files - one per line or empty if no changes cmd = 'git status --short' Shell.run( cmd ) end
changes?()
click to toggle source
# File lib/gitti/git.rb, line 85 def self.changes?() clean? == false; end
Also aliased as: dirty?
check()
click to toggle source
# File lib/gitti/git.rb, line 254 def self.check ## e.g. git fsck - check/validate hash of objects cmd = "git fsck" Shell.run( cmd ) end
clean?()
click to toggle source
git status –short returns empty stdout/list
# File lib/gitti/git.rb, line 83 def self.clean?() changes.empty?; end
clone( repo, name=nil, depth: nil )
click to toggle source
“setup” starter git commands
# File lib/gitti/git.rb, line 11 def self.clone( repo, name=nil, depth: nil ) cmd = "git clone" cmd << " --depth #{depth}" unless depth.nil? cmd << " #{repo}" cmd << " #{name}" unless name.nil? || name.empty? Shell.run( cmd ) end
commit( message )
click to toggle source
# File lib/gitti/git.rb, line 130 def self.commit( message ) ### todo/check: make message.nil? an ArgumentError - why? why not? ### if message.nil? || message.empty? cmd = 'git commit' cmd << %Q{ -m "#{message}"} Shell.run( cmd ) end
config( prop, show_origin: false, show_scope: false )
click to toggle source
query git configuration helpers
# File lib/gitti/git.rb, line 169 def self.config( prop, show_origin: false, show_scope: false ) ## find a better name e.g. config_get? why? why not? cmd = "git config" cmd << " --show-origin" if show_origin cmd << " --show-scope" if show_scope if prop.is_a?( Regexp ) ## note: use Regexp#source ## Returns the original string of the pattern. ## e.g. /ab+c/ix.source #=> "ab+c" ## Note that escape sequences are retained as is. ## /\x20\+/.source #=> "\\x20\\+" cmd << " --get-regexp #{prop.source}" else ## assume string cmd << " --get #{prop}" end Shell.run( cmd ) end
fast_forward()
click to toggle source
# File lib/gitti/git.rb, line 104 def self.fast_forward cmd = 'git pull --ff-only' Shell.run( cmd ) end
Also aliased as: ff
fetch()
click to toggle source
more (major) git commands
# File lib/gitti/git.rb, line 94 def self.fetch cmd = 'git fetch' Shell.run( cmd ) end
files()
click to toggle source
change git ls-files to git ls-tree … - why? why not?
- note: git ls-files will include stages files too not only committed ones!!!
git ls-tree –full-tree –name-only -r HEAD
1) --full-tree makes the command run as if you were in the repo's root directory. 2) -r recurses into subdirectories. Combined with --full-tree, this gives you all committed, tracked files. 3) --name-only removes SHA / permission info for when you just want the file paths. 4) HEAD specifies which branch you want the list of tracked, committed files for. You could change this to master or any other branch name, but HEAD is the commit you have checked out right now. see https://stackoverflow.com/questions/15606955/how-can-i-make-git-show-a-list-of-the-files-that-are-being-tracked
was:
# File lib/gitti/git.rb, line 157 def self.files ## was: e.g. git ls-files . or git ls-files *.rb or such ### todo/check: include --full-tree - why? why not? ## will ALWAYS list all files NOT depending on (current) working directory cmd = 'git ls-tree --full-tree --name-only -r HEAD' # was: 'git ls-files' Shell.run( cmd ) end
main?()
click to toggle source
# File lib/gitti/git.rb, line 201 def self.main? output = branch ## check for '* main' output.split( /\r?\n/ ).include?('* main') end
master?()
click to toggle source
# File lib/gitti/git.rb, line 196 def self.master? output = branch ## check for '* master' output.split( /\r?\n/ ).include?( '* master' ) end
mirror( repo )
click to toggle source
add -n (–no-checkout) – needed - why? why not? add –no-hardlinks – needed/recommended - why? why not?
# File lib/gitti/git.rb, line 53 def self.mirror( repo ) cmd = "git clone --mirror #{repo}" Shell.run( cmd ) end
origin()
click to toggle source
# File lib/gitti/git.rb, line 227 def self.origin ## e.g. git remote show origin cmd = "git remote show origin" Shell.run( cmd ) end
origin?()
click to toggle source
# File lib/gitti/git.rb, line 242 def self.origin? output = remote ## check for 'origin' output.split( /\r?\n/ ).include?( 'origin' ) end
pull()
click to toggle source
# File lib/gitti/git.rb, line 99 def self.pull cmd = 'git pull' Shell.run( cmd ) end
push()
click to toggle source
# File lib/gitti/git.rb, line 113 def self.push cmd = 'git push' Shell.run( cmd ) end
remote()
click to toggle source
# File lib/gitti/git.rb, line 237 def self.remote cmd = "git remote" Shell.run( cmd ) end
status( short: false )
click to toggle source
# File lib/gitti/git.rb, line 67 def self.status( short: false ) cmd = 'git status' cmd << " --short" if short Shell.run( cmd ) end
update()
click to toggle source
git remote update will update all of your branches
set to track remote ones, but not merge any changes in.
git fetch –all didn't exist at one time, so git remote update what more useful.
Now that --all has been added to git fetch, git remote update is not really necessary.
Differences between git remote update and fetch?
Is git remote update the equivalent of git fetch? see https://stackoverflow.com/questions/1856499/differences-between-git-remote-update-and-fetch/17512004#17512004 git fetch learned --all and --multiple options, to run fetch from many repositories, and --prune option to remove remote tracking branches that went stale. These make git remote update and git remote prune less necessary (there is no plan to remove remote update nor remote prune, though).
# File lib/gitti/git.rb, line 221 def self.update cmd = 'git remote update' Shell.run( cmd ) end
upstream()
click to toggle source
# File lib/gitti/git.rb, line 232 def self.upstream ## e.g. git remote show origin cmd = "git remote show upstream" Shell.run( cmd ) end
upstream?()
click to toggle source
# File lib/gitti/git.rb, line 247 def self.upstream? output = remote ## check for 'upstream' output.split( /\r?\n/ ).include?( 'upstream' ) end
version()
click to toggle source
standard git commands
# File lib/gitti/git.rb, line 62 def self.version cmd = 'git --version' Shell.run( cmd ) end