gitti 0.3.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cedf4859bb7b5521d3680c64f310f0a3456d1fbb
4
- data.tar.gz: 32e27bc777a0381db476082563b466d2438be218
3
+ metadata.gz: f1760a26ec9a86beb7d14f0c0e6022e3e4783aa6
4
+ data.tar.gz: 2037723116969b309e79c6004d930c63f46e5ae0
5
5
  SHA512:
6
- metadata.gz: 7b23e5ed7a99c1e632b0ccfecc7e9a3afc8aeee943884b72367e354e6829f2360cd3b8ba2f43e3bb8f54467fd262d72d7dcd54b26bfb29b647b7a9a93833c367
7
- data.tar.gz: ba2a18948bf92d98d9c4a09396ee95dcd05da757a3ce65aa633438530a43cdc133784054e3755fa72168eaa06c652beedc1aabeb8de73affd6a20b6f4b9c2d12
6
+ metadata.gz: 42c2602a52143c8d6f85ee32171d2eb6075b82112c10b89b50a5e80f52e3b664398e19b35cf089588e5581c6f11dc038d7b0980d00d5d5e210000a3cc1625c21
7
+ data.tar.gz: 24b130b13ae2a2a314e3a5b03e6cfb1467cb1f4cbeb90a2596251ff95f1cb9721dbb4f03a1fd9f43dcc0e9af951a0ca52a096f8bbe72fe28ee3346b0d114e80a
@@ -4,6 +4,8 @@ README.md
4
4
  Rakefile
5
5
  lib/gitti.rb
6
6
  lib/gitti/base.rb
7
+ lib/gitti/git.rb
8
+ lib/gitti/mirror.rb
7
9
  lib/gitti/project.rb
8
10
  lib/gitti/reposet.rb
9
11
  lib/gitti/version.rb
data/README.md CHANGED
@@ -1,120 +1,166 @@
1
- # gitti
2
-
3
- gitti gem - (yet) another (lite) git command line wrapper / library
4
-
5
- * home :: [github.com/rubycoco/gitti](https://github.com/rubycoco/gitti)
6
- * bugs :: [github.com/rubycoco/gitti/issues](https://github.com/rubycoco/gitti/issues)
7
- * gem :: [rubygems.org/gems/gitti](https://rubygems.org/gems/gitti)
8
- * rdoc :: [rubydoc.info/gems/gitti](http://rubydoc.info/gems/gitti)
9
-
10
-
11
-
12
- ## Usage
13
-
14
- `Git` • `GitProject`
15
-
16
-
17
- ### `Git` Class
18
-
19
- Use the `Git` class for "low-level / to the metal" git commands
20
- that run in your current working directory.
21
- Example:
22
-
23
- ``` ruby
24
-
25
- ###############
26
- ## "setup" starter git commands
27
-
28
- Git.clone( "git@github.com:rubycoco/gitti.git" )
29
- Git.clone( "git@github.com:rubycoco/gitti.git", "gitti-clone" )
30
-
31
- Git.mirror( "git@github.com:rubycoco/gitti.git" ) ## same as git clone --mirror
32
-
33
- #################
34
- ## standard git commands
35
-
36
- Git.version ## same as git --version
37
- Git.status
38
- Git.status( short: true ) ## same as Git.changes
39
- Git.changes ## same as git status --short
40
-
41
- #####################
42
- ## status helpers
43
-
44
- Git.clean?
45
- Git.changes?
46
- Git.dirty? ## alias for changes?
47
-
48
- #######
49
- ## more (major) git commands
50
-
51
- Git.fetch
52
- Git.pull
53
- Git.fast_forward ## same as git pull --ff-only
54
- Git.ff ## alias for fast_forward
55
- Git.push
56
- Git.add( "pathspec" )
57
- Git.add_all ## same as git --all
58
- Git.commit( "message" )
59
-
60
- Git.files ## same as git ls-tree --full-tree --name-only -r HEAD
61
- Git.config( "user.name" ) ## use --get option
62
- Git.config( "user.name", show_origin: true ) ## add --show-origin flag
63
- Git.config( "user.name", show_scope: true ) ## add --show-scope flag
64
-
65
- Git.config( /user/ ) ## use --get-regexp option
66
- Git.config( /user/, show_origin: true ) ## add --show-origin flag
67
- Git.config( /user/, show_scope: true ) ## add --show-scope flag
68
- ```
69
-
70
-
71
-
72
- ### `GitProject` Class
73
-
74
- Use the `GitProject` class for existing git repo(sitories)
75
- with workspace. Example:
76
-
77
- ``` ruby
78
- GitProject.open( "rubycoco/gitti" ) do |proj|
79
- proj.status
80
- proj.status( short: true )
81
- proj.changes
82
- proj.clean?
83
- proj.changes?
84
- proj.dirty?
85
-
86
- proj.fetch
87
- proj.pull
88
- proj.fast_forward
89
- proj.ff
90
-
91
- proj.push
92
-
93
- proj.add( "pathspec" )
94
- proj.add_all
95
- proj.commit( "message" )
96
-
97
- proj.files
98
- end
99
- ```
100
-
101
- That's it for now.
102
-
103
-
104
- ## Installation
105
-
106
- Use
107
-
108
- gem install gitti
109
-
110
- or add to your Gemfile
111
-
112
- gem 'gitti'
113
-
114
-
115
-
116
- ## License
117
-
118
- The `gitti` scripts are dedicated to the public domain.
119
- Use it as you please with no restrictions whatsoever.
120
-
1
+ # gitti
2
+
3
+ gitti gem - (yet) another (lite) git command line helper / wrapper
4
+
5
+ * home :: [github.com/rubycoco/gitti](https://github.com/rubycoco/gitti)
6
+ * bugs :: [github.com/rubycoco/gitti/issues](https://github.com/rubycoco/gitti/issues)
7
+ * gem :: [rubygems.org/gems/gitti](https://rubygems.org/gems/gitti)
8
+ * rdoc :: [rubydoc.info/gems/gitti](http://rubydoc.info/gems/gitti)
9
+
10
+
11
+
12
+ ## Usage
13
+
14
+ `Git` • `GitProject` • `GitMirror`
15
+
16
+
17
+ ### `Git` Class
18
+
19
+ Use the `Git` class for "low-level / to the metal" git commands
20
+ that run in your current working directory.
21
+ Example:
22
+
23
+ ``` ruby
24
+
25
+ ###############
26
+ ## "setup" starter git commands
27
+
28
+ Git.clone( "https://github.com/rubycoco/gitti.git" )
29
+ Git.clone( "https://github.com/rubycoco/gitti.git", "gitti-clone" )
30
+ # -or- -- if you have write / commit access use ssh
31
+ Git.clone( "git@github.com:rubycoco/gitti.git" )
32
+ Git.clone( "git@github.com:rubycoco/gitti.git", "gitti-clone" )
33
+
34
+ Git.mirror( "https://github.com/rubycoco/gitti.git" ) ## same as git clone --mirror
35
+
36
+ #################
37
+ ## standard git commands
38
+
39
+ Git.version ## same as git --version
40
+ Git.status
41
+ Git.status( short: true ) ## same as Git.changes
42
+ Git.changes ## same as git status --short
43
+
44
+ #####################
45
+ ## status helpers
46
+
47
+ Git.clean?
48
+ Git.changes?
49
+ Git.dirty? ## alias for changes?
50
+
51
+ #######
52
+ ## more (major) git commands
53
+
54
+ Git.fetch
55
+ Git.pull
56
+ Git.fast_forward ## same as git pull --ff-only
57
+ Git.ff ## alias for fast_forward
58
+ Git.push
59
+ Git.add( "pathspec" )
60
+ Git.add_all ## same as git --all
61
+ Git.commit( "message" )
62
+
63
+ Git.files ## same as git ls-tree --full-tree --name-only -r HEAD
64
+
65
+ Git.check ## same as git fsck
66
+ Git.fsck ## alias for check
67
+ Git.checksum ## another alias for check
68
+
69
+ Git.master? ## on master branch
70
+ Git.main? ## on main branch
71
+
72
+ Git.origin ## same as git remote show origin
73
+ Git.upstream ## same as git remote show upstream
74
+ Git.origin?
75
+ Git.upstream?
76
+
77
+ Git.config( "user.name" ) ## use --get option
78
+ Git.config( "user.name", show_origin: true ) ## add --show-origin flag
79
+ Git.config( "user.name", show_scope: true ) ## add --show-scope flag
80
+
81
+ Git.config( /user/ ) ## use --get-regexp option
82
+ Git.config( /user/, show_origin: true ) ## add --show-origin flag
83
+ Git.config( /user/, show_scope: true ) ## add --show-scope flag
84
+ ```
85
+
86
+
87
+
88
+ ### `GitProject` Class
89
+
90
+ Use the `GitProject` class for existing git repo(sitories)
91
+ with workspace. Example:
92
+
93
+ ``` ruby
94
+ GitProject.open( "rubycoco/gitti" ) do |proj|
95
+ proj.status
96
+ proj.status( short: true )
97
+ proj.changes
98
+ proj.clean?
99
+ proj.changes?
100
+ proj.dirty?
101
+
102
+ proj.fetch
103
+ proj.pull
104
+ proj.fast_forward
105
+ proj.ff
106
+
107
+ proj.push
108
+
109
+ proj.add( "pathspec" )
110
+ proj.add_all
111
+ proj.commit( "message" )
112
+
113
+ proj.files
114
+
115
+ proj.master?
116
+ proj.main?
117
+
118
+ proj.origin
119
+ proj.upstream
120
+ proj.origin?
121
+ proj.upstream?
122
+ end
123
+ ```
124
+
125
+
126
+ ### `GitMirror` Class
127
+
128
+ Use the `GitMirror` class for existing mirrored (bare) git repo(sitories)
129
+ without workspace. Example:
130
+
131
+ ``` ruby
132
+ GitMirror.open( "rubycoco/gitti.git" ) do |mirror|
133
+ mirror.update # sames as git remote update
134
+ end
135
+ ```
136
+
137
+
138
+
139
+ That's it for now.
140
+
141
+
142
+
143
+ ## Real World Usage
144
+
145
+ The [`monos`](https://github.com/rubycoco/monos) gem incl. some monorepo / mono source tree tools and (startup) scripts
146
+ that let you run git commands on multiple repos.
147
+
148
+
149
+
150
+ ## Installation
151
+
152
+ Use
153
+
154
+ gem install gitti
155
+
156
+ or add to your Gemfile
157
+
158
+ gem 'gitti'
159
+
160
+
161
+
162
+ ## License
163
+
164
+ The `gitti` scripts are dedicated to the public domain.
165
+ Use it as you please with no restrictions whatsoever.
166
+
data/Rakefile CHANGED
@@ -3,9 +3,9 @@ require './lib/gitti/version.rb'
3
3
 
4
4
  Hoe.spec 'gitti' do
5
5
 
6
- self.version = Gitti::VERSION
6
+ self.version = GittiCore::VERSION
7
7
 
8
- self.summary = 'gitti - (yet) another (lite) git command line wrapper / library'
8
+ self.summary = 'gitti - (yet) another (lite) git command line helper / wrapper'
9
9
  self.description = summary
10
10
 
11
11
  self.urls = { home: 'https://github.com/rubycoco/gitti' }
@@ -17,12 +17,13 @@ Hoe.spec 'gitti' do
17
17
  self.readme_file = 'README.md'
18
18
  self.history_file = 'CHANGELOG.md'
19
19
 
20
- self.extra_deps = []
20
+ self.extra_deps = [
21
+ ['computer', '>= 0.1.0' ],
22
+ ]
21
23
 
22
24
  self.licenses = ['Public Domain']
23
25
 
24
26
  self.spec_extras = {
25
27
  required_ruby_version: '>= 2.2.2'
26
28
  }
27
-
28
29
  end
@@ -1,44 +1,7 @@
1
- require 'pp'
2
- require 'time'
3
- require 'date' ## e.g. Date.today etc.
4
- require 'yaml'
5
- require 'json'
6
- require 'uri'
7
- require 'net/http'
8
- require "net/https"
9
- require 'open3'
10
- require 'fileutils' ## e.g. FileUtils.mkdir_p etc.
1
+ require_relative 'gitti/base'
11
2
 
3
+ ## note: auto include Gitti; for "modular" version use ("Sinatra-style")
4
+ ## require "gitti/base"
12
5
 
6
+ include Gitti
13
7
 
14
- # our own code
15
- require 'gitti/version' # note: let version always go first
16
- require 'gitti/base'
17
- require 'gitti/project'
18
- require 'gitti/reposet'
19
-
20
-
21
-
22
- module Gitti
23
- ## todo: change to GitHubRepoRef or GitHubProject
24
- ## or Git::GitHub or Git::Source::GitHub or such - why? why not?
25
- class GitHubRepo
26
- attr_reader :owner, :name
27
-
28
- def initialize( owner, name )
29
- @owner = owner ## use/rename to login or something - why? why not??
30
- @name = name # e.g. "rubylibs/webservice"
31
- end
32
-
33
- def ssh_clone_url
34
- ## check: use https: as default? for github - http:// still supported? or redirected?
35
- ## "http://github.com/#{@owner}/#{@name}"
36
- "git@github.com:#{@owner}/#{@name}.git"
37
- end
38
- end ## class GitHubRepo
39
- end ## module Gitti
40
-
41
-
42
-
43
- # say hello
44
- puts Gitti.banner ## if defined?( $RUBYCOCO_DEBUG )
@@ -1,220 +1,60 @@
1
- module Gitti
1
+ require 'computer' ## note: move shell execute for (re)use to its own (upstream) gem
2
2
 
3
- ## raised by Git::Shell.run -- check if top-level ShellError alread exists?
4
- ## use ShellError or RunError - why? why not?
5
- ## and make Git::Shell top-level e.g. Shell - why? why not?
6
- class GitError < StandardError
3
+ module Gitti
4
+ Shell = Computer::Shell
5
+ ShellError = Computer::ShellError
6
+ GitError = Computer::ShellError ## raised if git exec returns with non-zero exit - just use ShellError - why? why not?
7
+ ## raised by Git::Shell.run
8
+ ## todo/check: use ShellError or RunError - why? why not?
9
+ ## and make Git::Shell top-level e.g. Shell - why? why not?
10
+
11
+ ## differentiate into/use
12
+ ## GitShell.run/GitCmd.run() or such and Shell.run - why? why not?
7
13
  end
8
14
 
9
15
 
10
- class Git ## make Git a module - why? why not?
11
-
12
- ###
13
- ## todo/fix: change opts=nil to *args or such - why? why not?
14
-
15
-
16
- ###############
17
- ## "setup" starter git commands
18
-
19
- def self.clone( repo, name=nil )
20
- cmd = "git clone #{repo}"
21
- cmd << " #{name}" unless name.nil? || name.empty?
22
- Shell.run( cmd )
23
- end
24
-
25
- def self.mirror( repo )
26
- cmd = "git clone --mirror #{repo}"
27
- Shell.run( cmd )
28
- end
29
-
30
-
31
- #################
32
- ## standard git commands
33
-
34
- def self.version
35
- cmd = 'git --version'
36
- Shell.run( cmd )
37
- end
38
-
39
- def self.status( short: false )
40
- cmd = 'git status'
41
- cmd << " --short" if short
42
- Shell.run( cmd )
43
- end
44
-
45
- def self.changes ## same as git status --short - keep shortcut / alias - why? why not?
46
- ## returns changed files - one per line or empty if no changes
47
- cmd = 'git status --short'
48
- Shell.run( cmd )
49
- end
50
-
51
- #####################
52
- ## status helpers
53
16
 
54
- ## git status --short returns empty stdout/list
55
- def self.clean?() changes.empty?; end
17
+ # our own code
18
+ require 'gitti/version' # note: let version always go first
19
+ require 'gitti/git'
20
+ require 'gitti/project'
21
+ require 'gitti/mirror'
22
+ require 'gitti/reposet'
56
23
 
57
- def self.changes?() clean? == false; end ## reverse of clean?
58
- class << self
59
- alias_method :dirty?, :changes? ## add alias
60
- end
61
-
62
-
63
- #######
64
- ## more (major) git commands
65
24
 
66
- def self.fetch
67
- cmd = 'git fetch'
68
- Shell.run( cmd )
69
- end
70
-
71
- def self.pull
72
- cmd = 'git pull'
73
- Shell.run( cmd )
74
- end
75
-
76
- def self.fast_forward
77
- cmd = 'git pull --ff-only'
78
- Shell.run( cmd )
79
- end
80
- class << self
81
- alias_method :ff, :fast_forward ## add alias
82
- end
83
25
 
26
+ module Gitti
27
+ ## todo: change to GitHubRepoRef or GitHubProject
28
+ ## or Git::GitHub or Git::Source::GitHub or such - why? why not?
29
+ class GitHubRepo
30
+ attr_reader :owner, :name
84
31
 
85
- def self.push
86
- cmd = 'git push'
87
- Shell.run( cmd )
32
+ def initialize( owner, name )
33
+ @owner = owner ## use/rename to login or something - why? why not??
34
+ @name = name # e.g. "rubylibs/webservice"
88
35
  end
89
36
 
90
- def self.add( pathspec=nil ) ## e.g. git add . or git add *.rb or such
91
- cmd = 'git add'
92
- cmd << " #{pathspec}" unless pathspec.nil? || pathspec.empty?
93
- Shell.run( cmd )
94
- end
95
37
 
96
- def self.add_all
97
- cmd = 'git add --all'
98
- Shell.run( cmd )
38
+ def ssh_clone_url
39
+ ## check: use https: as default? for github - http:// still supported? or redirected?
40
+ ## "http://github.com/#{@owner}/#{@name}"
41
+ "git@github.com:#{@owner}/#{@name}.git"
99
42
  end
100
43
 
101
- def self.commit( message )
102
- ### todo/check: make message.nil? an ArgumentError - why? why not?
103
- ### if message.nil? || message.empty?
104
-
105
- cmd = 'git commit'
106
- cmd << %Q{ -m "#{message}"}
107
-
108
- Shell.run( cmd )
44
+ def http_clone_url ## use clone_url( http: true ) -- why? why not?
45
+ ## note: https is default for github - http:// gets redirected to https://
46
+ "http://github.com/#{@owner}/#{@name}"
109
47
  end
110
48
 
111
-
112
- #############
113
- # change git ls-files to git ls-tree ... - why? why not?
114
- ## - note: git ls-files will include stages files too
115
- # not only committed ones!!!
116
- #
117
- # git ls-tree --full-tree --name-only -r HEAD
118
- # 1) --full-tree makes the command run as if you were in the repo's root directory.
119
- # 2) -r recurses into subdirectories. Combined with --full-tree, this gives you all committed, tracked files.
120
- # 3) --name-only removes SHA / permission info for when you just want the file paths.
121
- # 4) HEAD specifies which branch you want the list of tracked, committed files for.
122
- # You could change this to master or any other branch name, but HEAD is the commit you have checked out right now.
123
- #
124
- # see https://stackoverflow.com/questions/15606955/how-can-i-make-git-show-a-list-of-the-files-that-are-being-tracked
125
- #
126
- # was:
127
-
128
- def self.files ## was: e.g. git ls-files . or git ls-files *.rb or such
129
- ### todo/check: include --full-tree - why? why not?
130
- ## will ALWAYS list all files NOT depending on (current) working directory
131
-
132
- cmd = 'git ls-tree --full-tree --name-only -r HEAD' # was: 'git ls-files'
133
- Shell.run( cmd )
134
- end
135
- ## add list_files or ls_files alias - why? why not?
136
-
137
-
138
- ########
139
- ## query git configuration helpers
140
- def self.config( prop,
141
- show_origin: false,
142
- show_scope: false ) ## find a better name e.g. config_get? why? why not?
143
- cmd = "git config"
144
- cmd << " --show-origin" if show_origin
145
- cmd << " --show-scope" if show_scope
146
-
147
- if prop.is_a?( Regexp )
148
- ## note: use Regexp#source
149
- ## Returns the original string of the pattern.
150
- ## e.g. /ab+c/ix.source #=> "ab+c"
151
- ## Note that escape sequences are retained as is.
152
- ## /\x20\+/.source #=> "\\x20\\+"
153
- cmd << " --get-regexp #{prop.source}"
154
- else ## assume string
155
- cmd << " --get #{prop}"
156
- end
157
-
158
- Shell.run( cmd )
49
+ def https_clone_url
50
+ "https://github.com/#{@owner}/#{@name}"
159
51
  end
160
52
 
161
53
 
162
- ### add more - why? why not?
163
- ##
164
- ## def remote_update( opts={} ) ## e.g. git remote update
165
- ## command "remote update"
166
- ## end
167
-
168
- ## todo/check: rename remote to shorthand/shortcut or something or to branch - why, why not??
169
- ## def remote_show( name='origin', opts={}) ## e.g. git remote show origin
170
- ## command "remote show #{name}"
171
- ## end
172
-
173
-
54
+ end ## class GitHubRepo
55
+ end ## module Gitti
174
56
 
175
57
 
176
58
 
177
- ###
178
- # use nested class for "base" for running commands - why? why not?
179
- class Shell
180
- def self.run( cmd )
181
- print "cmd exec >#{cmd}<..."
182
- stdout, stderr, status = Open3.capture3( cmd )
183
-
184
- if status.success?
185
- print " OK"
186
- print "\n"
187
- else
188
- print " FAIL (#{status.exitstatus})"
189
- print "\n"
190
- end
191
-
192
- unless stdout.empty?
193
- puts stdout
194
- end
195
-
196
- unless stderr.empty?
197
- ## todo/check: or use >2: or &2: or such
198
- ## stderr output not always an error (that is, exit status might be 0)
199
- puts "STDERR:"
200
- puts stderr
201
- end
202
-
203
- if status.success?
204
- stdout # return stdout string
205
- else
206
- puts "!! ERROR: cmd exec >#{cmd}< failed with exit status #{status.exitstatus}:"
207
- puts stderr
208
-
209
- ### todo/fix: do NOT use GitError here!!! make it more "general"
210
- ### use a Git::Shell.run() wrapper or such - why? why not?
211
- ## or use a Shell.git() or Shell.git_run() ???
212
- ## or pass in error class - why? why not?
213
- raise GitError, "cmd exec >#{cmd}< failed with exit status #{status.exitstatus}<: #{stderr}"
214
- end
215
- end
216
- end # class Git::Shell
217
-
218
- end # class Git
219
-
220
- end # module Gitti
59
+ # say hello
60
+ puts GittiCore.banner ## if defined?( $RUBYCOCO_DEBUG )
@@ -0,0 +1,265 @@
1
+ module Gitti
2
+
3
+ class Git ## make Git a module - why? why not?
4
+
5
+ ###
6
+ ## todo/fix: change opts=nil to *args or such - why? why not?
7
+
8
+ ###############
9
+ ## "setup" starter git commands
10
+
11
+ def self.clone( repo, name=nil, depth: nil )
12
+ cmd = "git clone"
13
+ cmd << " --depth #{depth}" unless depth.nil?
14
+ cmd << " #{repo}"
15
+ cmd << " #{name}" unless name.nil? || name.empty?
16
+ Shell.run( cmd )
17
+ end
18
+
19
+ ###
20
+ ## What's the difference between git clone --mirror and git clone --bare
21
+ ## see https://stackoverflow.com/questions/3959924/whats-the-difference-between-git-clone-mirror-and-git-clone-bare
22
+ ##
23
+ ## The git clone help page has this to say about --mirror:
24
+ ## > Set up a mirror of the remote repository. This implies --bare
25
+ ##
26
+ ## The difference is that when using --mirror, all refs are copied as-is.
27
+ ## This means everything: remote-tracking branches, notes, refs/originals/*
28
+ ## (backups from filter-branch). The cloned repo has it all.
29
+ ## It's also set up so that a remote update will re-fetch everything from the origin
30
+ ## (overwriting the copied refs). The idea is really to mirror the repository,
31
+ ## to have a total copy, so that you could for example host your central repo
32
+ ## in multiple places, or back it up. Think of just straight-up copying the repo,
33
+ ## except in a much more elegant git way.
34
+ ##
35
+ ## The new documentation pretty much says all this:
36
+ ## see https://git-scm.com/docs/git-clone
37
+ ##
38
+ ## --mirror
39
+ ## Set up a mirror of the source repository. This implies --bare.
40
+ ## Compared to --bare, --mirror not only maps local branches of the source
41
+ ## to local branches of the target, it maps all refs
42
+ ## (including remote-tracking branches, notes etc.) and sets up a refspec configuration
43
+ ## such that all these refs are overwritten by a git remote update
44
+ ## in the target repository.
45
+ ##
46
+ ## More Articles / Resources:
47
+ ## https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/duplicating-a-repository
48
+
49
+
50
+ ## add -n (--no-checkout) -- needed - why? why not?
51
+ ## add --no-hardlinks -- needed/recommended - why? why not?
52
+
53
+ def self.mirror( repo )
54
+ cmd = "git clone --mirror #{repo}"
55
+ Shell.run( cmd )
56
+ end
57
+
58
+
59
+ #################
60
+ ## standard git commands
61
+
62
+ def self.version
63
+ cmd = 'git --version'
64
+ Shell.run( cmd )
65
+ end
66
+
67
+ def self.status( short: false )
68
+ cmd = 'git status'
69
+ cmd << " --short" if short
70
+ Shell.run( cmd )
71
+ end
72
+
73
+ def self.changes ## same as git status --short - keep shortcut / alias - why? why not?
74
+ ## returns changed files - one per line or empty if no changes
75
+ cmd = 'git status --short'
76
+ Shell.run( cmd )
77
+ end
78
+
79
+ #####################
80
+ ## status helpers
81
+
82
+ ## git status --short returns empty stdout/list
83
+ def self.clean?() changes.empty?; end
84
+
85
+ def self.changes?() clean? == false; end ## reverse of clean?
86
+ class << self
87
+ alias_method :dirty?, :changes? ## add alias
88
+ end
89
+
90
+
91
+ #######
92
+ ## more (major) git commands
93
+
94
+ def self.fetch
95
+ cmd = 'git fetch'
96
+ Shell.run( cmd )
97
+ end
98
+
99
+ def self.pull
100
+ cmd = 'git pull'
101
+ Shell.run( cmd )
102
+ end
103
+
104
+ def self.fast_forward
105
+ cmd = 'git pull --ff-only'
106
+ Shell.run( cmd )
107
+ end
108
+ class << self
109
+ alias_method :ff, :fast_forward ## add alias
110
+ end
111
+
112
+
113
+ def self.push
114
+ cmd = 'git push'
115
+ Shell.run( cmd )
116
+ end
117
+
118
+ def self.add( *pathspecs ) ## e.g. git add . or git add *.rb or such
119
+ cmd = 'git add'
120
+ pathspecs = ['.'] if pathspecs.size == 0
121
+ cmd << " #{pathspecs.join('')}"
122
+ Shell.run( cmd )
123
+ end
124
+
125
+ def self.add_all
126
+ cmd = 'git add --all'
127
+ Shell.run( cmd )
128
+ end
129
+
130
+ def self.commit( message )
131
+ ### todo/check: make message.nil? an ArgumentError - why? why not?
132
+ ### if message.nil? || message.empty?
133
+
134
+ cmd = 'git commit'
135
+ cmd << %Q{ -m "#{message}"}
136
+
137
+ Shell.run( cmd )
138
+ end
139
+
140
+
141
+ #############
142
+ # change git ls-files to git ls-tree ... - why? why not?
143
+ ## - note: git ls-files will include stages files too
144
+ # not only committed ones!!!
145
+ #
146
+ # git ls-tree --full-tree --name-only -r HEAD
147
+ # 1) --full-tree makes the command run as if you were in the repo's root directory.
148
+ # 2) -r recurses into subdirectories. Combined with --full-tree, this gives you all committed, tracked files.
149
+ # 3) --name-only removes SHA / permission info for when you just want the file paths.
150
+ # 4) HEAD specifies which branch you want the list of tracked, committed files for.
151
+ # You could change this to master or any other branch name, but HEAD is the commit you have checked out right now.
152
+ #
153
+ # see https://stackoverflow.com/questions/15606955/how-can-i-make-git-show-a-list-of-the-files-that-are-being-tracked
154
+ #
155
+ # was:
156
+
157
+ def self.files ## was: e.g. git ls-files . or git ls-files *.rb or such
158
+ ### todo/check: include --full-tree - why? why not?
159
+ ## will ALWAYS list all files NOT depending on (current) working directory
160
+
161
+ cmd = 'git ls-tree --full-tree --name-only -r HEAD' # was: 'git ls-files'
162
+ Shell.run( cmd )
163
+ end
164
+ ## add list_files or ls_files alias - why? why not?
165
+
166
+
167
+ ########
168
+ ## query git configuration helpers
169
+ def self.config( prop,
170
+ show_origin: false,
171
+ show_scope: false ) ## find a better name e.g. config_get? why? why not?
172
+ cmd = "git config"
173
+ cmd << " --show-origin" if show_origin
174
+ cmd << " --show-scope" if show_scope
175
+
176
+ if prop.is_a?( Regexp )
177
+ ## note: use Regexp#source
178
+ ## Returns the original string of the pattern.
179
+ ## e.g. /ab+c/ix.source #=> "ab+c"
180
+ ## Note that escape sequences are retained as is.
181
+ ## /\x20\+/.source #=> "\\x20\\+"
182
+ cmd << " --get-regexp #{prop.source}"
183
+ else ## assume string
184
+ cmd << " --get #{prop}"
185
+ end
186
+
187
+ Shell.run( cmd )
188
+ end
189
+
190
+
191
+ def self.branch
192
+ cmd = 'git branch'
193
+ Shell.run( cmd )
194
+ end
195
+
196
+ def self.master?
197
+ output = branch ## check for '* master'
198
+ output.split( /\r?\n/ ).include?( '* master' )
199
+ end
200
+
201
+ def self.main?
202
+ output = branch ## check for '* main'
203
+ output.split( /\r?\n/ ).include?('* main')
204
+ end
205
+
206
+ ## git remote update will update all of your branches
207
+ ## set to track remote ones, but not merge any changes in.
208
+ ##
209
+ ## git fetch --all didn't exist at one time, so git remote update what more useful.
210
+ ## Now that --all has been added to git fetch, git remote update is not really necessary.
211
+ ##
212
+ ## Differences between git remote update and fetch?
213
+ ## Is git remote update the equivalent of git fetch?
214
+ ## see https://stackoverflow.com/questions/1856499/differences-between-git-remote-update-and-fetch/17512004#17512004
215
+ ##
216
+ ## git fetch learned --all and --multiple options,
217
+ ## to run fetch from many repositories,
218
+ ## and --prune option to remove remote tracking branches that went stale.
219
+ ## These make git remote update and git remote prune less necessary
220
+ ## (there is no plan to remove remote update nor remote prune, though).
221
+ def self.update
222
+ cmd = 'git remote update'
223
+ Shell.run( cmd )
224
+ end
225
+
226
+
227
+ def self.origin ## e.g. git remote show origin
228
+ cmd = "git remote show origin"
229
+ Shell.run( cmd )
230
+ end
231
+
232
+ def self.upstream ## e.g. git remote show origin
233
+ cmd = "git remote show upstream"
234
+ Shell.run( cmd )
235
+ end
236
+
237
+ def self.remote
238
+ cmd = "git remote"
239
+ Shell.run( cmd )
240
+ end
241
+
242
+ def self.origin?
243
+ output = remote ## check for 'origin'
244
+ output.split( /\r?\n/ ).include?( 'origin' )
245
+ end
246
+
247
+ def self.upstream?
248
+ output = remote ## check for 'upstream'
249
+ output.split( /\r?\n/ ).include?( 'upstream' )
250
+ end
251
+
252
+
253
+
254
+ def self.check ## e.g. git fsck - check/validate hash of objects
255
+ cmd = "git fsck"
256
+ Shell.run( cmd )
257
+ end
258
+ class << self
259
+ alias_method :fsck, :check ## add alias
260
+ alias_method :checksum, :check
261
+ end
262
+
263
+ end # class Git
264
+
265
+ end # module Gitti
@@ -0,0 +1,33 @@
1
+ module Gitti
2
+
3
+ class GitMirror
4
+ def self.open( path, &blk )
5
+ new( path ).open( &blk )
6
+ end
7
+
8
+ def self.update( path ) ### all-in-one convenience shortcut
9
+ new( path).open { |mirror| mirror.update }
10
+ end
11
+
12
+
13
+
14
+ def initialize( path )
15
+ raise ArgumentError, "dir >#{path}< not found; dir MUST already exist for GitMirror class - sorry" unless Dir.exist?( path )
16
+ ## todo/check: check for more dirs and files e.g.
17
+ ## /info,/objects,/refs, /hooks, HEAD, config, description -- why? why not?
18
+ raise ArgumentError, "dir >#{path}/objects< not found; dir MUST already be initialized with git for GitMirror class - sorry" unless Dir.exist?( "#{path}/objects" )
19
+ @path = path
20
+ end
21
+
22
+
23
+ def open( &blk )
24
+ Dir.chdir( @path ) do
25
+ blk.call( self )
26
+ end
27
+ end
28
+
29
+ def update() Git.update; end
30
+
31
+ end # class GitMirror
32
+ end # module Gitti
33
+
@@ -35,14 +35,27 @@ class GitProject
35
35
 
36
36
  def push() Git.push; end
37
37
 
38
- def add( pathspec ) Git.add( pathspec ); end
38
+ def add( *pathspecs ) Git.add( *pathspecs ); end
39
39
  def add_all() Git.add_all; end
40
40
  def commit( message ) Git.commit( message ); end
41
41
 
42
42
  def files() Git.files; end
43
43
 
44
- def run( cmd ) Git::Shell.run( cmd ); end
45
44
 
45
+ ### remote show origin|upstream|etc.
46
+ def remote() Git.remote; end
47
+ def origin() Git.origin; end
48
+ def upstream() Git.upstream; end
49
+ def origin?() Git.origin?; end
50
+ def upstream?() Git.upstream?; end
51
+
52
+ ### branch management
53
+ def branch() Git.branch; end
54
+ def master?() Git.master?; end
55
+ def main?() Git.main?; end
56
+
57
+
58
+ def run( cmd ) Git::Shell.run( cmd ); end
46
59
  end # class GitProject
47
60
  end # module Gitti
48
61
 
@@ -4,8 +4,9 @@ module Gitti
4
4
 
5
5
  class GitRepoSet ## todo: rename to Hash/Dict/List/Map or use GitHubRepoSet ??
6
6
 
7
- def self.from_file( path ) ## todo/fix: change to self.read - why? why not?
8
- hash = YAML.load_file( path )
7
+ def self.read( path )
8
+ txt = File.open( path, 'r:utf-8') { |f| f.read }
9
+ hash = YAML.load( txt )
9
10
  new( hash )
10
11
  end
11
12
 
@@ -14,19 +15,24 @@ def initialize( hash )
14
15
  @hash = hash
15
16
  end
16
17
 
18
+ def size
19
+ ## sum up total number of repos
20
+ @size ||= @hash.reduce(0) {|sum,(_,names)| sum+= names.size; sum }
21
+ end
22
+
17
23
  def each
18
- @hash.each do |key_with_counter,values|
24
+ @hash.each do |org_with_counter,names|
19
25
 
20
26
  ## remove optional number from key e.g.
21
27
  ## mrhydescripts (3) => mrhydescripts
22
28
  ## footballjs (4) => footballjs
23
29
  ## etc.
24
30
 
25
- key = key_with_counter.sub( /\s+\([0-9]+\)/, '' )
31
+ org = org_with_counter.sub( /\([0-9]+\)/, '' ).strip
26
32
 
27
- puts " -- #{key_with_counter} [#{key}] --"
33
+ ## puts " -- #{key_with_counter} [#{key}] --"
28
34
 
29
- yield( key, values )
35
+ yield( org, names )
30
36
  end
31
37
  end
32
38
 
@@ -1,7 +1,13 @@
1
1
 
2
- module Gitti
2
+ ### note: use a different module for version (meta) info
3
+ ### that is, GittiCore and NOT Gitti
4
+ ### why? do NOT "pollute" Gitti with MAJOR, MINOR, PATH, and
5
+ ### self.banner, self.root, etc.
6
+
7
+
8
+ module GittiCore ## todo/check: rename GittiBase or GittiMeta or such - why? why not?
3
9
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
4
- MINOR = 3
10
+ MINOR = 6
5
11
  PATCH = 0
6
12
  VERSION = [MAJOR,MINOR,PATCH].join('.')
7
13
 
@@ -14,7 +20,7 @@ module Gitti
14
20
  end
15
21
 
16
22
  def self.root
17
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
23
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
18
24
  end
19
- end # module Gitti
25
+ end # module GittiCore
20
26
 
@@ -6,7 +6,16 @@ require 'helper'
6
6
 
7
7
  class TestBase < MiniTest::Test
8
8
 
9
- include Gitti
9
+ def test_branch
10
+ Git.branch
11
+ assert_equal true, Git.master?
12
+ assert_equal false, Git.main?
13
+
14
+ Git.remote
15
+ assert_equal true, Git.origin?
16
+ assert_equal false, Git.upstream?
17
+ end
18
+
10
19
 
11
20
  def test_git_config
12
21
  puts "---"
metadata CHANGED
@@ -1,44 +1,64 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitti
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-05 00:00:00.000000000 Z
11
+ date: 2020-10-20 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: computer
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.1.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rdoc
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
- - - "~>"
31
+ - - ">="
18
32
  - !ruby/object:Gem::Version
19
33
  version: '4.0'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '7'
20
37
  type: :development
21
38
  prerelease: false
22
39
  version_requirements: !ruby/object:Gem::Requirement
23
40
  requirements:
24
- - - "~>"
41
+ - - ">="
25
42
  - !ruby/object:Gem::Version
26
43
  version: '4.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '7'
27
47
  - !ruby/object:Gem::Dependency
28
48
  name: hoe
29
49
  requirement: !ruby/object:Gem::Requirement
30
50
  requirements:
31
51
  - - "~>"
32
52
  - !ruby/object:Gem::Version
33
- version: '3.16'
53
+ version: '3.22'
34
54
  type: :development
35
55
  prerelease: false
36
56
  version_requirements: !ruby/object:Gem::Requirement
37
57
  requirements:
38
58
  - - "~>"
39
59
  - !ruby/object:Gem::Version
40
- version: '3.16'
41
- description: gitti - (yet) another (lite) git command line wrapper / library
60
+ version: '3.22'
61
+ description: gitti - (yet) another (lite) git command line helper / wrapper
42
62
  email: ruby-talk@ruby-lang.org
43
63
  executables: []
44
64
  extensions: []
@@ -53,6 +73,8 @@ files:
53
73
  - Rakefile
54
74
  - lib/gitti.rb
55
75
  - lib/gitti/base.rb
76
+ - lib/gitti/git.rb
77
+ - lib/gitti/mirror.rb
56
78
  - lib/gitti/project.rb
57
79
  - lib/gitti/reposet.rb
58
80
  - lib/gitti/version.rb
@@ -83,5 +105,5 @@ rubyforge_project:
83
105
  rubygems_version: 2.5.2
84
106
  signing_key:
85
107
  specification_version: 4
86
- summary: gitti - (yet) another (lite) git command line wrapper / library
108
+ summary: gitti - (yet) another (lite) git command line helper / wrapper
87
109
  test_files: []