gitti 0.2.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{HISTORY.md → CHANGELOG.md} +0 -0
- data/Manifest.txt +8 -3
- data/README.md +166 -20
- data/Rakefile +6 -7
- data/lib/gitti.rb +4 -25
- data/lib/gitti/base.rb +60 -0
- data/lib/gitti/git.rb +265 -0
- data/lib/gitti/mirror.rb +33 -0
- data/lib/gitti/project.rb +61 -0
- data/lib/gitti/reposet.rb +42 -0
- data/lib/gitti/version.rb +10 -5
- data/test/helper.rb +7 -0
- data/test/test_base.rb +43 -0
- metadata +29 -18
- data/lib/gitti/lib.rb +0 -118
- data/lib/gitti/support/reposet.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 82d9e96c41bfe2c9fa31a16a4370dd7ed22fe77d
|
4
|
+
data.tar.gz: f9fcafde391fbba16b951a4858dda109898e41dd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1691456f72d2502668611903944cc1540b48266f733ba29ff5994f681e7911382e8bea3b45d2e6061ef7cf570b56b78d0c3c39124ccde9e28b93ba2cfdcb33ad
|
7
|
+
data.tar.gz: 846f28155f8e0a36ff0e8064fff12389c6cfee5b5f13b69e454842a2554dc89cf72f38fd34e395a1094708018b240811420608112fe5fabc63495bc9e0c13ee9
|
data/{HISTORY.md → CHANGELOG.md}
RENAMED
File without changes
|
data/Manifest.txt
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
-
|
1
|
+
CHANGELOG.md
|
2
2
|
Manifest.txt
|
3
3
|
README.md
|
4
4
|
Rakefile
|
5
5
|
lib/gitti.rb
|
6
|
-
lib/gitti/
|
7
|
-
lib/gitti/
|
6
|
+
lib/gitti/base.rb
|
7
|
+
lib/gitti/git.rb
|
8
|
+
lib/gitti/mirror.rb
|
9
|
+
lib/gitti/project.rb
|
10
|
+
lib/gitti/reposet.rb
|
8
11
|
lib/gitti/version.rb
|
12
|
+
test/helper.rb
|
13
|
+
test/test_base.rb
|
data/README.md
CHANGED
@@ -1,20 +1,166 @@
|
|
1
|
-
# gitti
|
2
|
-
|
3
|
-
gitti gem - (yet) another (lite) git command line
|
4
|
-
|
5
|
-
* home :: [github.com/
|
6
|
-
* bugs :: [github.com/
|
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
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
Use
|
20
|
-
|
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,28 +3,27 @@ require './lib/gitti/version.rb'
|
|
3
3
|
|
4
4
|
Hoe.spec 'gitti' do
|
5
5
|
|
6
|
-
self.version =
|
6
|
+
self.version = GittiCore::VERSION
|
7
7
|
|
8
|
-
self.summary = 'gitti - (yet) another (lite) git command line
|
8
|
+
self.summary = 'gitti - (yet) another (lite) git command line helper / wrapper'
|
9
9
|
self.description = summary
|
10
10
|
|
11
|
-
self.urls =
|
11
|
+
self.urls = { home: 'https://github.com/rubycoco/gitti' }
|
12
12
|
|
13
13
|
self.author = 'Gerald Bauer'
|
14
14
|
self.email = 'ruby-talk@ruby-lang.org'
|
15
15
|
|
16
16
|
# switch extension to .markdown for gihub formatting
|
17
17
|
self.readme_file = 'README.md'
|
18
|
-
self.history_file = '
|
18
|
+
self.history_file = 'CHANGELOG.md'
|
19
19
|
|
20
20
|
self.extra_deps = [
|
21
|
-
['
|
21
|
+
['yorobot-shell', '>= 0.0.1' ],
|
22
22
|
]
|
23
23
|
|
24
24
|
self.licenses = ['Public Domain']
|
25
25
|
|
26
26
|
self.spec_extras = {
|
27
|
-
required_ruby_version: '>=
|
27
|
+
required_ruby_version: '>= 2.2.2'
|
28
28
|
}
|
29
|
-
|
30
29
|
end
|
data/lib/gitti.rb
CHANGED
@@ -1,28 +1,7 @@
|
|
1
|
-
|
1
|
+
require_relative 'gitti/base'
|
2
2
|
|
3
|
-
|
4
|
-
require
|
5
|
-
require 'yaml'
|
6
|
-
require 'date' ## e.g. Date.today etc.
|
3
|
+
## note: auto include Gitti; for "modular" version use ("Sinatra-style")
|
4
|
+
## require "gitti/base"
|
7
5
|
|
8
|
-
|
9
|
-
require "net/https"
|
10
|
-
require 'uri'
|
6
|
+
include Gitti
|
11
7
|
|
12
|
-
require 'fileutils' ## e.g. FileUtils.mkdir_p etc.
|
13
|
-
|
14
|
-
|
15
|
-
# 3rd party gems/libs
|
16
|
-
require 'logutils'
|
17
|
-
|
18
|
-
# our own code
|
19
|
-
require 'gitti/version' # note: let version always go first
|
20
|
-
require 'gitti/lib'
|
21
|
-
|
22
|
-
|
23
|
-
## todo/check: move to its own gem e.g. gitti-support later - why? why not??
|
24
|
-
require 'gitti/support/reposet'
|
25
|
-
|
26
|
-
|
27
|
-
# say hello
|
28
|
-
puts Gitti.banner if defined?( $RUBYLIBS_DEBUG )
|
data/lib/gitti/base.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'yorobot/shell' ## note: move shell execute for (re)use to its own (upstream) gem
|
2
|
+
|
3
|
+
module Gitti
|
4
|
+
Shell = Yorobot::Shell
|
5
|
+
ShellError = Yorobot::ShellError
|
6
|
+
GitError = Yorobot::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?
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
|
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'
|
23
|
+
|
24
|
+
|
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
|
31
|
+
|
32
|
+
def initialize( owner, name )
|
33
|
+
@owner = owner ## use/rename to login or something - why? why not??
|
34
|
+
@name = name # e.g. "rubylibs/webservice"
|
35
|
+
end
|
36
|
+
|
37
|
+
|
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"
|
42
|
+
end
|
43
|
+
|
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}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def https_clone_url
|
50
|
+
"https://github.com/#{@owner}/#{@name}"
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
end ## class GitHubRepo
|
55
|
+
end ## module Gitti
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
# say hello
|
60
|
+
puts GittiCore.banner ## if defined?( $RUBYCOCO_DEBUG )
|
data/lib/gitti/git.rb
ADDED
@@ -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
|
data/lib/gitti/mirror.rb
ADDED
@@ -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
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Gitti
|
2
|
+
|
3
|
+
class GitProject
|
4
|
+
def self.open( path, &blk )
|
5
|
+
new( path ).open( &blk )
|
6
|
+
end
|
7
|
+
|
8
|
+
def initialize( path )
|
9
|
+
raise ArgumentError, "dir >#{path}< not found; dir MUST already exist for GitProject class - sorry" unless Dir.exist?( path )
|
10
|
+
raise ArgumentError, "dir >#{path}/.git< not found; dir MUST already be initialized with git for GitProject class - sorry" unless Dir.exist?( "#{path}/.git" )
|
11
|
+
@path = path
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
def open( &blk )
|
16
|
+
## puts "Dir.getwd: #{Dir.getwd}"
|
17
|
+
Dir.chdir( @path ) do
|
18
|
+
blk.call( self )
|
19
|
+
end
|
20
|
+
## puts "Dir.getwd: #{Dir.getwd}"
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
def status( short: false ) Git.status( short: short ); end
|
25
|
+
def changes() Git.changes; end
|
26
|
+
def clean?() Git.clean?; end
|
27
|
+
def changes?() Git.changes?; end
|
28
|
+
alias_method :dirty?, :changes?
|
29
|
+
|
30
|
+
|
31
|
+
def fetch() Git.fetch; end
|
32
|
+
def pull() Git.pull; end
|
33
|
+
def fast_forward() Git.fast_forward; end
|
34
|
+
alias_method :ff, :fast_forward
|
35
|
+
|
36
|
+
def push() Git.push; end
|
37
|
+
|
38
|
+
def add( *pathspecs ) Git.add( *pathspecs ); end
|
39
|
+
def add_all() Git.add_all; end
|
40
|
+
def commit( message ) Git.commit( message ); end
|
41
|
+
|
42
|
+
def files() Git.files; end
|
43
|
+
|
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
|
59
|
+
end # class GitProject
|
60
|
+
end # module Gitti
|
61
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
|
2
|
+
module Gitti
|
3
|
+
|
4
|
+
|
5
|
+
class GitRepoSet ## todo: rename to Hash/Dict/List/Map or use GitHubRepoSet ??
|
6
|
+
|
7
|
+
def self.read( path )
|
8
|
+
txt = File.open( path, 'r:utf-8') { |f| f.read }
|
9
|
+
hash = YAML.load( txt )
|
10
|
+
new( hash )
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
def initialize( hash )
|
15
|
+
@hash = hash
|
16
|
+
end
|
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
|
+
|
23
|
+
def each
|
24
|
+
@hash.each do |org_with_counter,names|
|
25
|
+
|
26
|
+
## remove optional number from key e.g.
|
27
|
+
## mrhydescripts (3) => mrhydescripts
|
28
|
+
## footballjs (4) => footballjs
|
29
|
+
## etc.
|
30
|
+
|
31
|
+
org = org_with_counter.sub( /\([0-9]+\)/, '' ).strip
|
32
|
+
|
33
|
+
## puts " -- #{key_with_counter} [#{key}] --"
|
34
|
+
|
35
|
+
yield( org, names )
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end ## class GitRepoSet
|
40
|
+
|
41
|
+
end ## module Gitti
|
42
|
+
|
data/lib/gitti/version.rb
CHANGED
@@ -1,9 +1,14 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
|
3
|
-
module
|
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?
|
4
9
|
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
5
|
-
MINOR =
|
6
|
-
PATCH =
|
10
|
+
MINOR = 5
|
11
|
+
PATCH = 0
|
7
12
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
8
13
|
|
9
14
|
def self.version
|
@@ -17,5 +22,5 @@ module Gitti
|
|
17
22
|
def self.root
|
18
23
|
"#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
|
19
24
|
end
|
20
|
-
end # module
|
25
|
+
end # module GittiCore
|
21
26
|
|
data/test/helper.rb
ADDED
data/test/test_base.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
###
|
2
|
+
# to run use
|
3
|
+
# ruby -I ./lib -I ./test test/test_base.rb
|
4
|
+
|
5
|
+
require 'helper'
|
6
|
+
|
7
|
+
class TestBase < MiniTest::Test
|
8
|
+
|
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
|
+
|
19
|
+
|
20
|
+
def test_git_config
|
21
|
+
puts "---"
|
22
|
+
Git.config( 'user.name' )
|
23
|
+
Git.config( 'user.name', show_origin: true )
|
24
|
+
## Git.config( 'user.name', show_scope: true )
|
25
|
+
|
26
|
+
puts "---"
|
27
|
+
Git.config( /user/ ) ## note: pass in regex for regex match/search
|
28
|
+
Git.config( /user/, show_origin: true )
|
29
|
+
## Git.config( /user/, show_scope: true )
|
30
|
+
|
31
|
+
puts "---"
|
32
|
+
Git.config( /user\./ ) ## note: pass in regex for regex match/search
|
33
|
+
|
34
|
+
puts "---"
|
35
|
+
## note: if NOT found Git.config will exit(1) !!!
|
36
|
+
## Git.config( /proxy/, show_origin: true )
|
37
|
+
## Git.config( /http/, show_origin: true )
|
38
|
+
|
39
|
+
puts "---"
|
40
|
+
end
|
41
|
+
|
42
|
+
end # class TestBase
|
43
|
+
|
metadata
CHANGED
@@ -1,75 +1,86 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitti
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.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:
|
11
|
+
date: 2020-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: yorobot-shell
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.0.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.0.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rdoc
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '4.0'
|
34
|
+
- - "<"
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '7'
|
34
37
|
type: :development
|
35
38
|
prerelease: false
|
36
39
|
version_requirements: !ruby/object:Gem::Requirement
|
37
40
|
requirements:
|
38
|
-
- - "
|
41
|
+
- - ">="
|
39
42
|
- !ruby/object:Gem::Version
|
40
43
|
version: '4.0'
|
44
|
+
- - "<"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '7'
|
41
47
|
- !ruby/object:Gem::Dependency
|
42
48
|
name: hoe
|
43
49
|
requirement: !ruby/object:Gem::Requirement
|
44
50
|
requirements:
|
45
51
|
- - "~>"
|
46
52
|
- !ruby/object:Gem::Version
|
47
|
-
version: '3.
|
53
|
+
version: '3.22'
|
48
54
|
type: :development
|
49
55
|
prerelease: false
|
50
56
|
version_requirements: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - "~>"
|
53
59
|
- !ruby/object:Gem::Version
|
54
|
-
version: '3.
|
55
|
-
description: gitti - (yet) another (lite) git command line
|
60
|
+
version: '3.22'
|
61
|
+
description: gitti - (yet) another (lite) git command line helper / wrapper
|
56
62
|
email: ruby-talk@ruby-lang.org
|
57
63
|
executables: []
|
58
64
|
extensions: []
|
59
65
|
extra_rdoc_files:
|
60
|
-
-
|
66
|
+
- CHANGELOG.md
|
61
67
|
- Manifest.txt
|
62
68
|
- README.md
|
63
69
|
files:
|
64
|
-
-
|
70
|
+
- CHANGELOG.md
|
65
71
|
- Manifest.txt
|
66
72
|
- README.md
|
67
73
|
- Rakefile
|
68
74
|
- lib/gitti.rb
|
69
|
-
- lib/gitti/
|
70
|
-
- lib/gitti/
|
75
|
+
- lib/gitti/base.rb
|
76
|
+
- lib/gitti/git.rb
|
77
|
+
- lib/gitti/mirror.rb
|
78
|
+
- lib/gitti/project.rb
|
79
|
+
- lib/gitti/reposet.rb
|
71
80
|
- lib/gitti/version.rb
|
72
|
-
|
81
|
+
- test/helper.rb
|
82
|
+
- test/test_base.rb
|
83
|
+
homepage: https://github.com/rubycoco/gitti
|
73
84
|
licenses:
|
74
85
|
- Public Domain
|
75
86
|
metadata: {}
|
@@ -83,7 +94,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
83
94
|
requirements:
|
84
95
|
- - ">="
|
85
96
|
- !ruby/object:Gem::Version
|
86
|
-
version:
|
97
|
+
version: 2.2.2
|
87
98
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
99
|
requirements:
|
89
100
|
- - ">="
|
@@ -91,8 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
91
102
|
version: '0'
|
92
103
|
requirements: []
|
93
104
|
rubyforge_project:
|
94
|
-
rubygems_version: 2.2
|
105
|
+
rubygems_version: 2.5.2
|
95
106
|
signing_key:
|
96
107
|
specification_version: 4
|
97
|
-
summary: gitti - (yet) another (lite) git command line
|
108
|
+
summary: gitti - (yet) another (lite) git command line helper / wrapper
|
98
109
|
test_files: []
|
data/lib/gitti/lib.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Gitti
|
4
|
-
|
5
|
-
class GitError < StandardError
|
6
|
-
end
|
7
|
-
|
8
|
-
class GitLib
|
9
|
-
|
10
|
-
#######################
|
11
|
-
## "open" commands
|
12
|
-
|
13
|
-
def clone( repo, opts={} )
|
14
|
-
command "clone #{repo}"
|
15
|
-
end
|
16
|
-
|
17
|
-
def mirror( repo, opts={} )
|
18
|
-
command "clone --mirror #{repo}"
|
19
|
-
end
|
20
|
-
|
21
|
-
#########################
|
22
|
-
## more commands
|
23
|
-
|
24
|
-
def status( opts={} ) ## e.g. git status
|
25
|
-
command "status"
|
26
|
-
end
|
27
|
-
|
28
|
-
def pull( opts={} ) ## e.g. git pull
|
29
|
-
command "pull"
|
30
|
-
end
|
31
|
-
|
32
|
-
def remote_update( opts={} ) ## e.g. git remote update
|
33
|
-
command "remote update"
|
34
|
-
end
|
35
|
-
|
36
|
-
## todo/check: rename remote to shorthand/shortcut or something or to branch - why, why not??
|
37
|
-
def remote_show( name='origin', opts={}) ## e.g. git remote show origin
|
38
|
-
command "remote show #{name}"
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
|
-
def add( pathspec='.', opts={} ) ## e.g. git add .
|
43
|
-
command "add #{pathspec}"
|
44
|
-
end
|
45
|
-
|
46
|
-
def commit( message, opts={} ) ## e.g. git commit -m "up standings"
|
47
|
-
command "commit -m \"#{message}\""
|
48
|
-
end
|
49
|
-
|
50
|
-
def push( opts={} ) ## e.g. git push
|
51
|
-
command "push"
|
52
|
-
end
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
## todo/fix:
|
57
|
-
## add last_exit or something ?? why? why not??
|
58
|
-
|
59
|
-
def command( cmd )
|
60
|
-
## note: for now use Kernel#system for calling external git command
|
61
|
-
##
|
62
|
-
|
63
|
-
cmdline = "git #{cmd}"
|
64
|
-
puts " trying >#{cmdline}< in (#{Dir.pwd})..."
|
65
|
-
|
66
|
-
result = nil
|
67
|
-
result = system( cmdline )
|
68
|
-
|
69
|
-
pp result
|
70
|
-
|
71
|
-
# note: Kernel#system returns
|
72
|
-
# - true if the command gives zero exit status
|
73
|
-
# - false for non zero exit status
|
74
|
-
# - nil if command execution fails
|
75
|
-
# An error status is available in $?.
|
76
|
-
|
77
|
-
if result.nil?
|
78
|
-
puts "*** error was #{$?}"
|
79
|
-
fail "[Kernel.system] command execution failed >#{cmdline}< - #{$?}"
|
80
|
-
elsif result ## true => zero exit code (OK)
|
81
|
-
puts 'OK' ## zero exit; assume OK
|
82
|
-
true ## assume ok
|
83
|
-
else ## false => non-zero exit code (ERR/NOK)
|
84
|
-
puts "*** error: non-zero exit - #{$?} !!" ## non-zero exit (e.g. 1,2,3,etc.); assume error
|
85
|
-
|
86
|
-
## log error for now ???
|
87
|
-
# File.open( './errors.log', 'a' ) do |f|
|
88
|
-
# f.write "#{Time.now} -- repo #{@owner}/#{@name} - command execution failed - non-zero exit\n"
|
89
|
-
# end
|
90
|
-
raise GitError.new( "command execution failed >#{cmdline}< - non-zero exit (#{$?})" )
|
91
|
-
end
|
92
|
-
end # method command
|
93
|
-
end # class Lib
|
94
|
-
|
95
|
-
|
96
|
-
module Git
|
97
|
-
## todo/fix: use "shared" singelton lib - why? why not??
|
98
|
-
def self.clone( repo, opts={} ) GitLib.new.clone( repo, opts ); end
|
99
|
-
def self.mirror( repo, opts={} ) GitLib.new.mirror( repo, opts ); end
|
100
|
-
|
101
|
-
def self.pull( opts={} ) GitLib.new.pull( opts ); end
|
102
|
-
def self.remote_update( opts={} ) GitLib.new.remote_update( opts ); end
|
103
|
-
def self.remote_show( name='origin', opts={}) GitLib.new.remote_show( name, opts ); end
|
104
|
-
|
105
|
-
def self.status( opts={} ) GitLib.new.status( opts ); end
|
106
|
-
def self.pull( opts={} ) GitLib.new.pull( opts ); end
|
107
|
-
def self.add( pathspec='.', opts={} ) GitLib.new.add( pathspec, opts ); end
|
108
|
-
def self.commit( message, opts={} ) GitLib.new.commit( message, opts ); end
|
109
|
-
def self.push( opts={} ) GitLib.new.push( opts ); end
|
110
|
-
end # module Git
|
111
|
-
|
112
|
-
end # module Gitti
|
113
|
-
|
114
|
-
|
115
|
-
### convenience top level Git module - check if defined? make optional? why? why not??
|
116
|
-
## Git = Gitti::Git
|
117
|
-
|
118
|
-
# for now use include Gitti - why? why not??
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
module Gitti
|
4
|
-
|
5
|
-
|
6
|
-
class GitRepoSet ## todo: rename to Hash/Dict/List/Map or use GitHubRepoSet ??
|
7
|
-
|
8
|
-
def self.from_file( path )
|
9
|
-
hash = YAML.load_file( path )
|
10
|
-
self.new( hash )
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
def initialize( hash )
|
15
|
-
@hash = hash
|
16
|
-
end
|
17
|
-
|
18
|
-
def each
|
19
|
-
@hash.each do |key_with_counter,values|
|
20
|
-
|
21
|
-
## remove optional number from key e.g.
|
22
|
-
## mrhydescripts (3) => mrhydescripts
|
23
|
-
## footballjs (4) => footballjs
|
24
|
-
## etc.
|
25
|
-
|
26
|
-
key = key_with_counter.sub( /\s+\([0-9]+\)/, '' )
|
27
|
-
|
28
|
-
puts " -- #{key_with_counter} [#{key}] --"
|
29
|
-
|
30
|
-
yield( key, values )
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end ## class GitRepoSet
|
35
|
-
|
36
|
-
end ## module Gitti
|
37
|
-
|