Class: Gitti::Git
- Inherits:
-
Object
- Object
- Gitti::Git
- Defined in:
- lib/gitti/git.rb
Overview
make Git a module - why? why not?
Class Method Summary collapse
-
.add(*pathspecs) ⇒ Object
e.g.
- .add_all ⇒ Object
- .branch ⇒ Object
-
.changes ⇒ Object
same as git status –short - keep shortcut / alias - why? why not?.
-
.changes? ⇒ Boolean
(also: dirty?)
reverse of clean?.
-
.check ⇒ Object
(also: fsck, checksum)
e.g.
-
.clean? ⇒ Boolean
git status –short returns empty stdout/list.
-
.clone(repo, name = nil, depth: nil) ⇒ Object
“setup” starter git commands.
- .commit(message) ⇒ Object
-
.config(prop, show_origin: false, show_scope: false) ⇒ Object
query git configuration helpers.
- .fast_forward ⇒ Object (also: ff)
-
.fetch ⇒ Object
more (major) git commands.
-
.files ⇒ Object
change git ls-files to git ls-tree …
- .main? ⇒ Boolean
- .master? ⇒ Boolean
-
.mirror(repo) ⇒ Object
add -n (–no-checkout) – needed - why? why not? add –no-hardlinks – needed/recommended - why? why not?.
-
.origin ⇒ Object
e.g.
- .origin? ⇒ Boolean
- .pull ⇒ Object
- .push ⇒ Object
- .remote ⇒ Object
- .status(short: false) ⇒ Object
-
.update ⇒ Object
git remote update will update all of your branches set to track remote ones, but not merge any changes in.
-
.upstream ⇒ Object
e.g.
- .upstream? ⇒ Boolean
-
.version ⇒ Object
standard git commands.
Class Method Details
.add(*pathspecs) ⇒ Object
e.g. git add . or git add *.rb or such
118 119 120 121 122 123 |
# 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 ⇒ Object
125 126 127 128 |
# File 'lib/gitti/git.rb', line 125 def self.add_all cmd = 'git add --all' Shell.run( cmd ) end |
.branch ⇒ Object
191 192 193 194 |
# File 'lib/gitti/git.rb', line 191 def self.branch cmd = 'git branch' Shell.run( cmd ) end |
.changes ⇒ Object
same as git status –short - keep shortcut / alias - why? why not?
73 74 75 76 77 |
# 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? ⇒ Boolean Also known as: dirty?
reverse of clean?
85 |
# File 'lib/gitti/git.rb', line 85 def self.changes?() clean? == false; end |
.check ⇒ Object Also known as: fsck, checksum
e.g. git fsck - check/validate hash of objects
254 255 256 257 |
# 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? ⇒ Boolean
git status –short returns empty stdout/list
83 |
# File 'lib/gitti/git.rb', line 83 def self.clean?() changes.empty?; end |
.clone(repo, name = nil, depth: nil) ⇒ Object
“setup” starter git commands
11 12 13 14 15 16 17 |
# 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) ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/gitti/git.rb', line 130 def self.commit( ) ### todo/check: make message.nil? an ArgumentError - why? why not? ### if message.nil? || message.empty? cmd = 'git commit' cmd << %Q{ -m "#{}"} Shell.run( cmd ) end |
.config(prop, show_origin: false, show_scope: false) ⇒ Object
query git configuration helpers
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# 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 ⇒ Object Also known as: ff
104 105 106 107 |
# File 'lib/gitti/git.rb', line 104 def self.fast_forward cmd = 'git pull --ff-only' Shell.run( cmd ) end |
.fetch ⇒ Object
more (major) git commands
94 95 96 97 |
# File 'lib/gitti/git.rb', line 94 def self.fetch cmd = 'git fetch' Shell.run( cmd ) end |
.files ⇒ Object
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:
157 158 159 160 161 162 163 |
# 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? ⇒ Boolean
201 202 203 204 |
# File 'lib/gitti/git.rb', line 201 def self.main? output = branch ## check for '* main' output.split( /\r?\n/ ).include?('* main') end |
.master? ⇒ Boolean
196 197 198 199 |
# File 'lib/gitti/git.rb', line 196 def self.master? output = branch ## check for '* master' output.split( /\r?\n/ ).include?( '* master' ) end |
.mirror(repo) ⇒ Object
add -n (–no-checkout) – needed - why? why not? add –no-hardlinks – needed/recommended - why? why not?
53 54 55 56 |
# File 'lib/gitti/git.rb', line 53 def self.mirror( repo ) cmd = "git clone --mirror #{repo}" Shell.run( cmd ) end |
.origin ⇒ Object
e.g. git remote show origin
227 228 229 230 |
# 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? ⇒ Boolean
242 243 244 245 |
# File 'lib/gitti/git.rb', line 242 def self.origin? output = remote ## check for 'origin' output.split( /\r?\n/ ).include?( 'origin' ) end |
.pull ⇒ Object
99 100 101 102 |
# File 'lib/gitti/git.rb', line 99 def self.pull cmd = 'git pull' Shell.run( cmd ) end |
.push ⇒ Object
113 114 115 116 |
# File 'lib/gitti/git.rb', line 113 def self.push cmd = 'git push' Shell.run( cmd ) end |
.remote ⇒ Object
237 238 239 240 |
# File 'lib/gitti/git.rb', line 237 def self.remote cmd = "git remote" Shell.run( cmd ) end |
.status(short: false) ⇒ Object
67 68 69 70 71 |
# File 'lib/gitti/git.rb', line 67 def self.status( short: false ) cmd = 'git status' cmd << " --short" if short Shell.run( cmd ) end |
.update ⇒ Object
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).
221 222 223 224 |
# File 'lib/gitti/git.rb', line 221 def self.update cmd = 'git remote update' Shell.run( cmd ) end |
.upstream ⇒ Object
e.g. git remote show origin
232 233 234 235 |
# 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? ⇒ Boolean
247 248 249 250 |
# File 'lib/gitti/git.rb', line 247 def self.upstream? output = remote ## check for 'upstream' output.split( /\r?\n/ ).include?( 'upstream' ) end |
.version ⇒ Object
standard git commands
62 63 64 65 |
# File 'lib/gitti/git.rb', line 62 def self.version cmd = 'git --version' Shell.run( cmd ) end |