git_cli 0.11.4 → 0.13.6

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
  SHA256:
3
- metadata.gz: 8c844000e4bc30d57687dc1e43d0fc0e46744db06376e00508c6d534be047d54
4
- data.tar.gz: 54ab8c78a819454e0d037c8b73b66003757fc735e828700749bf8010504233c2
3
+ metadata.gz: 65d5e6d16badac8b20440fb70e3551540ea515d09da007043f6db1ae8c112d3f
4
+ data.tar.gz: 87ab402f4559425b7d092d175165584e1a55e087022c8c8e17a7cb7b9801487b
5
5
  SHA512:
6
- metadata.gz: 20314f09b8b43ea58b8e19e7fc9f9260622b45b9c63ee84b754f0f59ebe52e89b41142c6c2df9e98480d6ec1807e9f814877c4f43344b9b6bbcd27952c4d1c12
7
- data.tar.gz: 7054bf58a5bb2fb0221d5b6dbf5c28be0371e0f1a02e63ab8d47765c04a77e2a707e770da14c3ec2089844998c15ddbe0e40b05c410092ed640782a9fc88d0cd
6
+ metadata.gz: ab769484650486cca4441285e97085c7beba91e133e31608bf37aac39ae5fbe04c4ac5cdf74e7b93eee91c6f2fd15bcf8f78c84c903902f4ada4316f97c801d0
7
+ data.tar.gz: 914652362807973632c56b01a026079d9143cfc15b442eb2f8045a42b3d2d35a618cf88724bb611bad508f1c57fc1ec4592e750f2b7549e34b17de6b025fe354
data/Gemfile CHANGED
@@ -6,4 +6,3 @@ gemspec
6
6
  gem "rake", "~> 12.0"
7
7
  gem "minitest", "~> 5.0"
8
8
 
9
- #gem 'gvcs', git: 'gvcs', branch: 'master'
data/Gemfile.lock CHANGED
@@ -1,44 +1,43 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git_cli (0.11.4)
5
- gvcs
4
+ git_cli (0.13.6)
6
5
  ptools (~> 1.4.0)
7
- teLogger
8
- toolrack
6
+ teLogger (> 0.2)
7
+ toolrack (> 0.23)
9
8
 
10
9
  GEM
11
10
  remote: https://rubygems.org/
12
11
  specs:
13
- colorize (0.8.1)
14
- devops_assist (0.3.11)
15
- git_cli
16
- git_cli_prompt (~> 0.3.3)
17
- gvcs
18
- teLogger
19
- toolrack
20
- tty-prompt
21
- gem-release (2.2.2)
22
- git_cli_prompt (0.3.4)
23
- teLogger
24
- toolrack
25
- tty-prompt
26
- gvcs (0.1.2)
27
- minitest (5.18.0)
12
+ colorize (1.1.0)
13
+ diff-lcs (1.5.0)
14
+ minitest (5.20.0)
28
15
  pastel (0.8.0)
29
16
  tty-color (~> 0.5)
30
17
  ptools (1.4.3)
31
18
  rake (12.3.3)
32
- release-gem (0.1.10)
19
+ release-gem (0.1.29)
33
20
  colorize
34
21
  git_cli
35
- gvcs
36
22
  teLogger
37
23
  toolrack
38
24
  tty-command
39
25
  tty-prompt
26
+ rspec (3.12.0)
27
+ rspec-core (~> 3.12.0)
28
+ rspec-expectations (~> 3.12.0)
29
+ rspec-mocks (~> 3.12.0)
30
+ rspec-core (3.12.2)
31
+ rspec-support (~> 3.12.0)
32
+ rspec-expectations (3.12.3)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.12.0)
35
+ rspec-mocks (3.12.6)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.12.0)
38
+ rspec-support (3.12.1)
40
39
  teLogger (0.2.2)
41
- toolrack (0.22.0)
40
+ toolrack (0.23.2)
42
41
  tty-color (0.6.0)
43
42
  tty-command (0.10.1)
44
43
  pastel (~> 0.8)
@@ -57,12 +56,11 @@ PLATFORMS
57
56
  x86_64-linux
58
57
 
59
58
  DEPENDENCIES
60
- devops_assist
61
- gem-release
62
59
  git_cli!
63
60
  minitest (~> 5.0)
64
61
  rake (~> 12.0)
65
62
  release-gem
63
+ rspec
66
64
 
67
65
  BUNDLED WITH
68
- 2.2.28
66
+ 2.4.19
data/README.md CHANGED
@@ -11,52 +11,203 @@ This codes are tested using git version 2.25.1, Linux x86\_64
11
11
  Add this line to your application's Gemfile:
12
12
 
13
13
  ```ruby
14
- gem 'gvcs'
15
14
  gem 'git_cli'
16
15
  ```
17
16
 
18
17
  And then execute:
19
18
 
20
- $ bundle install
19
+ $ bundle install
21
20
 
22
21
  Or install it yourself as:
23
22
 
24
- $ gem install gvcs
25
23
  $ gem install git_cli
26
24
 
27
25
  ## Usage
28
26
 
29
- This gem is intended to be the provider for Gvcs generic API. It is used together with [Gvcs](https://github.com/chrisliaw/gvcs).
30
-
31
27
  Example usage:
32
28
 
33
29
  ```ruby
34
- require 'gvcs'
35
- # require git_cli after gvcs because git_cli will initialize the gvcs classes with appropriate methods
36
30
  require 'git_cli'
37
31
 
38
- # Loading the provider.
39
- # in this case is git_cli
40
- vcs = Gvcs::Vcs.new
32
+ # vcs is encapsulation of general functions (read below)
33
+ vcs = GitCli::Vcs.new
41
34
  vcs.init(path) # init workspace at the given path
35
+ vcs.clone("/source/repos", "/destination/repos") # clone a project
42
36
 
43
- @ws = Gvcs::Workspace.new(vcs, path)
44
- # @ws now can invoke all supported git operations
37
+ workspace = GitCli::Workspace.new(vcs, "/any/git/repository")
38
+ # workspace now can invoke all supported git operations
45
39
 
46
40
  ```
47
-
48
-
49
- ## Development
50
-
51
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
-
53
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
-
55
- ## Contributing
56
-
57
- Bug reports and pull requests are welcome on GitHub at https://github.com/chrisliaw/git_cli. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/chrisliaw/git_cli/blob/master/CODE_OF_CONDUCT.md).
58
-
59
-
60
- ## Code of Conduct
61
41
 
62
- Everyone interacting in the GitCli project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/chrisliaw/git_cli/blob/master/CODE_OF_CONDUCT.md).
42
+ ## Supported GIT Operation
43
+
44
+ The following operations are supported on the git command line:
45
+ - Generall functions (to make a directory become git workspace)
46
+ - vcs.init("/path/to/new/workspace")
47
+ - vcs.clone("/source/repos","/path/to/workspace")
48
+ - Workspace command
49
+ - workspace.root\_path
50
+ > git rev-parse --show-toplevel
51
+ - workspace.is\_workspace?
52
+ - Call git status see if error thrown
53
+ - workspace.repos
54
+ - Returns list of remote repositories
55
+ - workspace.clean?
56
+ - Return true if there is no new,deleted,modified and staged files
57
+ - workspace.add("/path/a","/path/b","/path/c/a")
58
+ > git add
59
+ - workspace.remove\_staging("/path/a","/path/b","/path/c/a")
60
+ > git reset
61
+ - workspace.remove\_vcs("/path/a","/path/b","/path/c/a")
62
+ > git rm --cached
63
+ - workspace.commit("commit message", { files: ["/path/a"."/path/b"] })
64
+ > git commit /path/a /path/b -m "commit message"
65
+ - workspace.commit\_all("commit message")
66
+ > git commit -am
67
+ - workspace.status
68
+ - Returns list of GitCli::Delta::VCSItem carries attributes @path, @full and @type
69
+ > git status
70
+ - workspace.modFiles
71
+ - Returns modified files (GitCli::Delta::VCSItem) in an array
72
+ > git diff --name-only --diff-filter=M
73
+ - workspace.cftFiles
74
+ - Returns conflicted files (GitCli::Delta::VCSItem) in an array
75
+ > git diff --name-only --diff-filter=U
76
+ - workspace.newFiles
77
+ - Returns and files (non tracked) (GitCli::Delta::VCSItem) in an array
78
+ > git ls-files --others --exclude-standard --directory
79
+ - workspace.delFiles
80
+ - Returns deleted files (GitCli::Delta::VCSItem) in an array
81
+ > git ls-files -d
82
+ - workspace.stgFiles
83
+ - Returns staged files (GitCli::Delta::VCSItem) in an array
84
+ > git diff --name-only --cached
85
+ - workspace.reset\_file\_changes("/path/to/file")
86
+ > git checkout --
87
+ - workspace.reset\_all\_changes
88
+ > git reset --hard
89
+ - workspace.calculat\_distance("origin/HEAD","HEAD")
90
+ - Returns integer value how far is it
91
+ > git rev-list 'origin/HEAD'..'HEAD' --count
92
+ - workspace.is\_local\_ahead\_of\_remote?("origin/HEAD","branch-main")
93
+ - Aggregated from calculate\_distance() with default _to_ value fixed at "HEAD"
94
+ - Returns boolean
95
+ - workspace.is\_remote\_ahead\_of\_local?("origin/HEAD","branch-main")
96
+ - aggregated from calculate\_distance() with default _from_ value fixed at "HEAD"
97
+ - Returns boolean
98
+ - workspace.push("origin","master")
99
+ > git push origin master
100
+ - workspace.push\_with\_tags("origin","master")
101
+ > git push origin master --tags
102
+ - workspace.pull("origin","master")
103
+ > git pull origin master
104
+ - workspace.current\_branch
105
+ - Returns branch name
106
+ > git branch --show-current
107
+ - workspace.local\_branches
108
+ - Return local branches in an array
109
+ > git branch
110
+ - workspace.remote\_branches
111
+ - Return remote branches in an array
112
+ > git branch -r
113
+ - workspace.all\_branches
114
+ - Concate output of local\_branches and remote\_branches
115
+ - Returns array
116
+ - workspace.switch\_branch("new-branch")
117
+ > git checkout new-branch
118
+ - workspace.create\_branch("new-branch")
119
+ > git branch new-branch
120
+ - workspace.download\_all\_remote\_branches\_name
121
+ > git fetch -all
122
+ - workspace.merge\_branch("development")
123
+ > git merge development
124
+ - workspace.delete\_branch("development")
125
+ > git branch -d development
126
+ - workspace.diff
127
+ > git diff
128
+ - workspace.diff\_file("/path/a")
129
+ > git diff /path/a
130
+ - workspace.diff\_branch("master/HEAD","development/HEAD")
131
+ > git diff master/HEAD..development/HEAD
132
+ - workspace.diff\_working\_with\_last\_commit
133
+ > git diff HEAD^ HEAD
134
+ - workspace.diff\_index\_with\_last\_commit
135
+ > git diff --cached
136
+ - workspace.ignore("/path/a","/path/b")
137
+ - Append entries into .gitignore file
138
+ - workspace.ignore\_rules
139
+ - Read the .gitignore files and returns its content in an array
140
+ - workspace.update\_ignore\_rules("\*.log")
141
+ - Add non file entries into .gitignore
142
+ - workspace.show\_log(commit\_id)
143
+ > git show commit\_id
144
+ - workspace.all\_tags
145
+ - Returns array
146
+ > git tag
147
+ - workspace.tag\_info("tagname", "%H|%ad|%an|%s")
148
+ > git show tagname --format="%H|%ad|%an|%s"
149
+ - workspace.create\_tag(tagname)
150
+ > git tag tagname
151
+ - workspace.create\_tag(tagname, message)
152
+ > git tag -a tagname -m message
153
+ - workspace.create\_tag\_from\_commit(tagname, commit)
154
+ > git tag -a tagname commit
155
+ - workspace.create\_tag\_from\_commit(tagname, commit, message)
156
+ > git tag -a tagname -m message commit
157
+ - workspace.fetch\_tag\_to\_local
158
+ > git fetch --all --tags
159
+ - workspace.show\_tag\_detail(tagname)
160
+ > git show tagname
161
+ - workspace.delete\_tag(tagname)
162
+ > git tag -d tagname
163
+ - workspace.delete\_remote\_tag("origin","tagname")
164
+ > git push origin --delete tagname
165
+ - workspace.checkout\_tag(tagname, branch)
166
+ > git checkout tags/tagname -b branch
167
+ - workspace.tag\_points\_at?("HEAD")
168
+ - Return boolean
169
+ > git tag --points-at HEAD
170
+ - workspace.remote\_config
171
+ - Return Hash with repos name as key, points to hash with "push" or "fetch" as key
172
+ > git remote -vv
173
+ - workspace.add\_remote(name, url)
174
+ > git remote add name url
175
+ - workspace.remove\_remote(name)
176
+ > git remote remove name
177
+ - workspace.stash\_changes(msg)
178
+ > git stash save "msg"
179
+ - workspace.stash\_all\_chanegs(msg)
180
+ > git stash save --include-untracked
181
+ - workspace.stash\_all\_chanegs(msg, true)
182
+ > git stash save --include-untracked(-u) --all(-a)
183
+ - workspace.stash\_list
184
+ - Returns boolean and hash of stash info
185
+ > git stash list
186
+ - workspace.stash\_restore
187
+ > git stash apply
188
+ - workspace.stash\_restore(id)
189
+ > git stash apply id --> ID can be obtained from stash\_list. Something like "stash@{0}"
190
+ - workspace.stash\_restore\_and\_remove
191
+ > git stash pop
192
+ - workspace.stash\_restore\_and\_remove(id)
193
+ > git stash pop id --> ID can be obtained from stash\_list. Something like "stash@{0}"
194
+ - workspace.stash\_to\_new\_branch(branch)
195
+ > git stash branch
196
+ - workspace.stash\_to\_new\_branch(branch, id)
197
+ > git stash branch id
198
+ - workspace.stash\_clear
199
+ > git stash clear
200
+ - workspace.stash\_remove
201
+ > git stash drop
202
+ - workspace.stash\_remove(id)
203
+ > git stash drop id
204
+
205
+
206
+
207
+ ## Return Value
208
+
209
+ Unless otherwise stated, the API shall return an array, with 1st element is the boolean status value running the command line (taken from $?) and 2nd element shall be the standard output of the running command. Note though all command was run with flag '2>&1' which effectively redirected the STDERR to STDOUT which should be captured by the program.
210
+
211
+ This is due to all running of command line is via the backtick (\`) method. The reason to use this is backtick allow interaction with user. If there is an input needed, backtick will actually wait user input at the prompt, although not ideal, but it is the simplest and easiest for now.
212
+
213
+
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
3
 
4
- require "devops_assist"
4
+ #require "devops_assist"
5
5
 
6
6
  Rake::TestTask.new(:test) do |t|
7
7
  t.libs << "test"
data/git_cli.gemspec CHANGED
@@ -28,13 +28,12 @@ Gem::Specification.new do |spec|
28
28
  spec.require_paths = ["lib"]
29
29
 
30
30
  #spec.add_dependency "tlogger"
31
- spec.add_dependency 'teLogger'
32
- spec.add_dependency "toolrack"
33
- spec.add_dependency "gvcs"
31
+ spec.add_dependency 'teLogger', "> 0.2"
32
+ spec.add_dependency "toolrack", "> 0.23"
33
+ #spec.add_dependency "gvcs"
34
34
  spec.add_dependency "ptools", "~> 1.4.0"
35
35
 
36
- #spec.add_development_dependency 'devops_helper' #, ">= 0.2.0"
37
- spec.add_development_dependency 'devops_assist' #, ">= 0.2.0"
38
- spec.add_development_dependency 'gem-release'
36
+ spec.add_development_dependency 'rspec'
37
+
39
38
  spec.add_development_dependency 'release-gem'
40
39
  end
@@ -25,15 +25,14 @@ module GitCli
25
25
 
26
26
  raise_if_empty(paths, "Given path to add is empty", GitCliException)
27
27
 
28
- paths = [paths] if not paths.is_a?(Array)
29
-
30
28
  cmd = []
31
29
  cmd << "cd"
32
30
  cmd << @wsPath
33
31
  cmd << "&&"
34
32
  cmd << @vcs.exe_path
35
33
  cmd << "add"
36
- cmd.append(paths.join(" "))
34
+
35
+ cmd.append(GitCli::Workspace.args_to_string_array(paths).join(" "))
37
36
  cmdln = cmd.join " "
38
37
 
39
38
  log_debug "Add : #{cmdln}"
@@ -51,20 +50,19 @@ module GitCli
51
50
  alias :add :add_to_staging
52
51
  alias :add_staging :add_to_staging
53
52
 
54
- def remove_from_staging(paths)
53
+ def remove_from_staging(*paths)
55
54
  check_vcs
56
55
 
57
56
  raise_if_empty(paths, "Given path to reset is empty", GitCliException)
58
57
 
59
- paths = [paths] if not paths.is_a?(Array)
60
-
61
58
  cmd = []
62
59
  cmd << "cd"
63
60
  cmd << @wsPath
64
61
  cmd << "&&"
65
62
  cmd << @vcs.exe_path
66
63
  cmd << "reset"
67
- cmd.append(paths)
64
+
65
+ cmd.append(GitCli::Workspace.args_to_string_array(paths))
68
66
  cmdln = cmd.join " "
69
67
 
70
68
  log_debug "reset : #{cmdln}"
@@ -76,21 +74,20 @@ module GitCli
76
74
  end # remove_from_staging
77
75
  alias :remove_staging :remove_from_staging
78
76
 
79
- def remove_from_vcs(paths)
77
+ def remove_from_vcs(*paths)
80
78
 
81
79
  check_vcs
82
80
 
83
81
  raise_if_empty(paths, "Given path to remove from VCS is empty", GitCliException)
84
82
 
85
- paths = [paths] if not paths.is_a?(Array)
86
-
87
83
  cmd = []
88
84
  cmd << "cd"
89
85
  cmd << @wsPath
90
86
  cmd << "&&"
91
87
  cmd << @vcs.exe_path
92
88
  cmd << "rm --cached"
93
- cmd.append(paths)
89
+
90
+ cmd.append(GitCli::Workspace.args_to_string_array(paths))
94
91
  cmdln = cmd.join " "
95
92
 
96
93
  log_debug "Remove from git version control : #{cmdln}"
@@ -100,6 +97,7 @@ module GitCli
100
97
  end
101
98
 
102
99
  end # remove_from_vcs
100
+ alias :remove_vcs :remove_from_vcs
103
101
 
104
102
  def commit(message, opts = { })
105
103
  check_vcs
@@ -116,7 +114,7 @@ module GitCli
116
114
  cmd << @vcs.exe_path
117
115
  cmd << "commit"
118
116
  if not_empty?(files)
119
- cmd << files.join(" ")
117
+ cmd << GitCli::Workspace.args_to_string_array(files).join(" ")
120
118
  end
121
119
  cmd << "-m"
122
120
  cmd << "\"#{msg}\""
data/lib/git_cli/delta.rb CHANGED
@@ -193,6 +193,16 @@ module GitCli
193
193
 
194
194
  end
195
195
  end # modified files
196
+ def modified
197
+ modified_files.reverse
198
+ end
199
+ def modFiles
200
+ modified.first
201
+ end
202
+ def has_modified_file?
203
+ modFiles.length > 0
204
+ end
205
+ alias_method :has_modified_files?, :has_modified_file?
196
206
 
197
207
  def conflicted_files
198
208
 
@@ -229,6 +239,16 @@ module GitCli
229
239
 
230
240
  end
231
241
  end # conflicted files
242
+ def conflicted
243
+ conflicted_files.reverse
244
+ end
245
+ def cftFiles
246
+ conflicted.first
247
+ end
248
+ def has_conflicted_file?
249
+ ctfFiles.length > 0
250
+ end
251
+ alias_method :has_conflicted_files?, :has_conflicted_file?
232
252
 
233
253
  def new_files
234
254
 
@@ -265,6 +285,13 @@ module GitCli
265
285
  end
266
286
 
267
287
  end # new_files
288
+ def newFiles
289
+ new_files.reverse.first
290
+ end
291
+ def has_new_file?
292
+ newFiles.length >0
293
+ end
294
+ alias_method :has_new_files?, :has_new_file?
268
295
 
269
296
  def deleted_files
270
297
 
@@ -301,6 +328,16 @@ module GitCli
301
328
  end
302
329
 
303
330
  end # deleted_files
331
+ def deleted
332
+ deleted_files.reverse
333
+ end
334
+ def delFiles
335
+ deleted.first
336
+ end
337
+ def has_deleted_file?
338
+ delFiles.length > 0
339
+ end
340
+ alias_method :has_deleted_files?, :has_deleted_file?
304
341
 
305
342
  def staged_files
306
343
 
@@ -337,6 +374,16 @@ module GitCli
337
374
  end
338
375
 
339
376
  end # staged_files
377
+ def staged
378
+ staged_files.reverse
379
+ end
380
+ def stgFiles
381
+ staged.first
382
+ end
383
+ def has_staged_file?
384
+ stgFiles.length > 0
385
+ end
386
+ alias_method :has_staged_files?, :has_staged_file?
340
387
 
341
388
  def reset_file_changes(path)
342
389
 
@@ -32,32 +32,35 @@ module GitCli
32
32
  end
33
33
 
34
34
  def ignore_rules
35
- st, root = workspace_root
35
+ #st, root = workspace_root
36
+ root = workspace_root
36
37
  root.strip!
37
- if st
38
+ #if st
38
39
  rulesFile = File.join(root,".gitignore")
39
40
  if File.exist?(rulesFile)
40
41
  File.open(rulesFile,"r") do |f|
41
42
  @cont = f.read
42
43
  end
43
- @cont
44
+ #@cont
45
+ @cont.each_line.to_a.delete_if { |l| l.strip.empty? }
44
46
  else
45
- ""
47
+ []
46
48
  end
47
- else
48
- ""
49
- end
49
+ #else
50
+ # []
51
+ #end
50
52
  end
51
53
 
52
54
  def update_ignore_rules(rules)
53
- st, root = workspace_root
55
+ #st, root = workspace_root
56
+ root = workspace_root
54
57
  root.strip!
55
- if st
58
+ #if st
56
59
  rulesFile = File.join(root,".gitignore")
57
60
  File.open(rulesFile,"w") do |f|
58
61
  f.write rules
59
62
  end
60
- end
63
+ #end
61
64
  log_debug ".gitignore files is updated!"
62
65
  [true,".gitignore file is updated"]
63
66
  end
@@ -66,17 +69,18 @@ module GitCli
66
69
  def with_ignore_file(mode = "a", &block)
67
70
  mode = "a" if is_empty?(mode)
68
71
  if block
69
- st, root = workspace_root
72
+ #st, root = workspace_root
73
+ root = workspace_root
70
74
  root.strip!
71
- if st
75
+ #if st
72
76
  igPath = File.join(root,".gitignore")
73
77
  FileUtils.touch(igPath) if not File.exist?(igPath)
74
78
  File.open(igPath,mode) do |f|
75
79
  block.call(f)
76
80
  end
77
- else
78
- raise GitCliException, "Cannot get workspace root. Probably not a GIT workspace?"
79
- end
81
+ #else
82
+ # raise GitCliException, "Cannot get workspace root. Probably not a GIT workspace?"
83
+ #end
80
84
  end
81
85
  end
82
86
 
data/lib/git_cli/init.rb CHANGED
@@ -23,7 +23,7 @@ require_relative 'global'
23
23
  module GitCli
24
24
  module Init
25
25
 
26
- def init(path)
26
+ def init(path, bare = false)
27
27
  # from Core module
28
28
  gpath = exe_path
29
29
 
@@ -32,6 +32,9 @@ module GitCli
32
32
  #cmd << "&&"
33
33
  cmd << gpath
34
34
  cmd << "init"
35
+ if bare
36
+ cmd << "--bare"
37
+ end
35
38
  cmd << File.expand_path(path)
36
39
 
37
40
  cmdln = cmd.join(" ")
data/lib/git_cli/log.rb CHANGED
@@ -64,6 +64,7 @@ module GitCli
64
64
  end
65
65
 
66
66
  end # log
67
+ alias_method :log, :logs
67
68
 
68
69
  def show_log(cid)
69
70
 
data/lib/git_cli/push.rb CHANGED
@@ -15,11 +15,13 @@
15
15
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
17
 
18
+ require_relative 'branch'
18
19
 
19
20
  module GitCli
20
21
  module Push
22
+ include Branch
21
23
 
22
- def push_changes(repos, branch = "master")
24
+ def push_changes(repos, branch = nil)
23
25
  check_vcs
24
26
  #check_repos
25
27
  raise_if_empty(repos, "Push to repository name cannot be empty", GitCliException)
@@ -33,6 +35,9 @@ module GitCli
33
35
  cmd << @vcs.exe_path
34
36
  cmd << "push"
35
37
  cmd << repos
38
+ if is_empty?(branch)
39
+ branch = current_branch
40
+ end
36
41
  cmd << branch
37
42
 
38
43
  cmdln = cmd.join " "
@@ -44,7 +49,7 @@ module GitCli
44
49
  end # push_changes
45
50
  alias :push :push_changes
46
51
 
47
- def push_changes_with_tags(repos, branch = "master")
52
+ def push_changes_with_tags(repos, branch = nil)
48
53
  check_vcs
49
54
  #check_repos
50
55
  raise_if_empty(repos, "Push to repository name cannot be empty", GitCliException)
@@ -58,6 +63,9 @@ module GitCli
58
63
  cmd << @vcs.exe_path
59
64
  cmd << "push"
60
65
  cmd << repos
66
+ if is_empty?(branch)
67
+ branch = current_branch
68
+ end
61
69
  cmd << branch
62
70
  cmd << "--tags"
63
71
 
data/lib/git_cli/stash.rb CHANGED
@@ -24,9 +24,10 @@ module GitCli
24
24
  # due to various reason. i.e. urgent fix, hot patch etc
25
25
 
26
26
  #
27
- # Save all the temporary changes so branch switch is possible
27
+ # Save all changes so branch switch is possible
28
+ # Excluding untracked files
28
29
  #
29
- def stash_changes(msg, include_untracked = true)
30
+ def stash_changes(msg)
30
31
 
31
32
  check_vcs
32
33
 
@@ -44,20 +45,59 @@ module GitCli
44
45
  cmd << msg2
45
46
  end
46
47
 
47
- # always include untracked since the stash condition
48
- # is played using scenario under development and must
49
- # switch branch for any reasons
50
- if include_untracked
51
- cmd << "--include-untracked"
48
+ cmdln = cmd.join(" ")
49
+ log_debug "Stash changes : #{cmdln}"
50
+ res = os_exec(cmdln) do |st, res|
51
+ [st.success?, res]
52
+ end
53
+
54
+ end # stash changes - changed files only
55
+
56
+ #
57
+ # Save all the temporary changes so the workspace will be clean
58
+ # for other operation
59
+ #
60
+ # This operation only stash: modified files (already in git workspace)
61
+ # and new files (not in git workspace yet)
62
+ #
63
+ # If flag includes_ignore_file is true, include ignored file too
64
+ #
65
+ def stash_all_changes(msg, includes_ignore_file = false)
66
+
67
+ check_vcs
68
+
69
+ cmd = []
70
+ cmd << "cd"
71
+ cmd << @wsPath
72
+ cmd << "&&"
73
+ cmd << @vcs.exe_path
74
+ cmd << "stash"
75
+ cmd << "save"
76
+
77
+ if not_empty?(msg)
78
+ # have to escape the message for command line purposes
79
+ msg2 = msg.gsub("\"","\\\"").gsub("\\","\\\\")
80
+ cmd << msg2
81
+ end
82
+
83
+ cmd << "--include-untracked"
84
+
85
+ if includes_ignore_file == true
86
+ cmd << "--all"
52
87
  end
53
88
 
54
89
  cmdln = cmd.join(" ")
55
- log_debug "Stash changes : #{cmdln}"
90
+ if includes_ignore_file
91
+ log_debug "Stash all changes (including untracked and ignored files) : #{cmdln}"
92
+ else
93
+ log_debug "Stash all changes (including untracked files) : #{cmdln}"
94
+ end
56
95
  res = os_exec(cmdln) do |st, res|
57
96
  [st.success?, res]
58
97
  end
59
98
 
60
- end # stash changes
99
+ end # stash all changes - including untrack files
100
+
61
101
 
62
102
  #
63
103
  # List all saved temporary changes
@@ -162,7 +202,7 @@ module GitCli
162
202
  cmd << @wsPath
163
203
  cmd << "&&"
164
204
  cmd << @vcs.exe_path
165
- cmd << "stash branch"
205
+ cmd << "stash"
166
206
  cmd << branch
167
207
 
168
208
  if not is_empty?(id)
data/lib/git_cli/tags.rb CHANGED
@@ -37,7 +37,7 @@ module GitCli
37
37
  res = os_exec(cmdln) do |st, res|
38
38
 
39
39
  if st.success?
40
- res.strip
40
+ res.strip.each_line.to_a.map { |v| v.strip }
41
41
  #[true, res.strip!]
42
42
  else
43
43
  raise TagError, res
@@ -300,7 +300,10 @@ module GitCli
300
300
  cmd << @wsPath
301
301
  cmd << "&&"
302
302
  cmd << @vcs.exe_path
303
- cmd << "push origin --delete"
303
+ cmd << "push"
304
+ cmd << repos
305
+ cmd << "--delete"
306
+ #cmd << "push origin --delete"
304
307
  cmd << tag
305
308
 
306
309
  cmdln = cmd.join(" ")
@@ -15,5 +15,5 @@
15
15
  # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
 
17
17
  module GitCli
18
- VERSION = "0.11.4"
18
+ VERSION = "0.13.6"
19
19
  end
data/lib/git_cli.rb CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  require "git_cli/version"
18
18
 
19
- require 'gvcs'
19
+ #require 'gvcs'
20
20
  require 'toolrack'
21
21
 
22
22
  require_relative "git_cli/git_core"
@@ -47,7 +47,8 @@ module GitCli
47
47
 
48
48
  def os_exec(path, &block)
49
49
 
50
- Gvcs::Config.instance.command_output.puts("Git command : #{path}") if Gvcs::Config.instance.is_show_vcs_command?
50
+ #Gvcs::Config.instance.command_output.puts("Git command : #{path}") if Gvcs::Config.instance.is_show_vcs_command?
51
+ log_debug("Git command : #{path}")
51
52
 
52
53
  # redirect stderr to stdout
53
54
  path = "#{path} 2>&1"
@@ -85,9 +86,12 @@ module GitCli
85
86
  def dry_run
86
87
  @dry_run.nil? ? false : @dry_run
87
88
  end
89
+
88
90
  end # common operations
89
91
 
90
- class Gvcs::Vcs
92
+ #class Gvcs::Vcs
93
+ class Vcs
94
+ include TR::CondUtils
91
95
  include GitCli::Common
92
96
  include GitCli::GitCore
93
97
  include GitCli::Init
@@ -118,7 +122,9 @@ module GitCli
118
122
  end
119
123
  end # WsCommon
120
124
 
121
- class Gvcs::Workspace
125
+ #class Gvcs::Workspace
126
+ class Workspace
127
+ include TR::CondUtils
122
128
  include GitCli::Common
123
129
  include WsCommon
124
130
  include GitCli::AddCommit
@@ -142,7 +148,7 @@ module GitCli
142
148
  raise_if_empty(path, "Workspace path cannot be empty", GitCliException)
143
149
 
144
150
  if is_empty?(vcs)
145
- @vcs = Gvcs::Vcs.new
151
+ @vcs = GitCli::Vcs.new
146
152
  else
147
153
  @vcs = vcs
148
154
  end
@@ -214,9 +220,11 @@ module GitCli
214
220
  res = os_exec(cmdln) do |st, res|
215
221
 
216
222
  if st.success?
217
- @wsRoot = [true, res.strip]
223
+ @wsRoot = res.strip
224
+ #@wsRoot = [true, res.strip]
218
225
  else
219
- @wsRoot = [false, res.strip]
226
+ raise GitCliException, "Failure executing : #{cmdln} \nError was : #{res.strip}"
227
+ #@wsRoot = [false, res.strip]
220
228
  end
221
229
  end
222
230
 
@@ -225,11 +233,14 @@ module GitCli
225
233
  @wsRoot
226
234
 
227
235
  end # workspace_root
236
+ #class <<self
237
+ alias_method :root_path, :workspace_root
238
+ #end
228
239
 
229
240
  def load_remote_to_repos
230
241
  conf = remote_config
231
242
  conf.each do |k,v|
232
- repo = Gvcs::Repository.new(k, v.values.first)
243
+ repo = GitCli::Repository.new(k, v.values.first)
233
244
  repo.support_fetch if v.keys.include?("fetch")
234
245
  repo.support_push if v.keys.include?("push")
235
246
  add_repos(repo)
@@ -249,14 +260,39 @@ module GitCli
249
260
  dd, df = deleted_files
250
261
  sd, sf = staged_files
251
262
 
252
- (nd.length == 0 and nf.length == 0 and md.length == 0 and mf.length == 0 and dd.length == 0 and df.length == 0 and sd.length == 0 and sf.length == 0)
263
+ #log_debug "New Dir : #{nd}"
264
+ #log_debug "Mod Dir : #{md}"
265
+ #log_debug "Del Dir : #{dd}"
266
+ #log_debug "Stg Dir : #{sd}"
267
+
268
+ #(nd.length == 0 and nf.length == 0 and md.length == 0 and mf.length == 0 and dd.length == 0 and df.length == 0 and sd.length == 0 and sf.length == 0)
269
+ (nf.length == 0 and mf.length == 0 and df.length == 0 and sf.length == 0)
253
270
  end
254
271
  alias_method :clean?, :is_clean?
272
+ alias_method :clear?, :is_clean?
273
+
274
+ def self.args_to_string_array(*args)
275
+ res = []
276
+ args.each do |e|
277
+ case e
278
+ when Delta::VCSItem
279
+ res << e.path
280
+ when Array
281
+ res.concat(args_to_string_array(*e))
282
+ when String
283
+ res << e
284
+ else
285
+ res << e.to_s
286
+ end
287
+ end
288
+ res
289
+ end
255
290
 
256
291
  end # Gvcs::Workspace
257
292
 
258
293
 
259
- class Gvcs::Repository
294
+ #class Gvcs::Repository
295
+ class Repository
260
296
 
261
297
  attr_reader :sslVerify
262
298
  attr_reader :name, :url
@@ -294,3 +330,9 @@ module GitCli
294
330
  end # repository
295
331
 
296
332
  end
333
+
334
+ # backward compatibility
335
+ #Gvcs::Vcs = GitCli::Vcs
336
+ #Gvcs::Workspace = GitCli::Workspace
337
+ #Gvcs::Repository = GitCli::Repository
338
+
metadata CHANGED
@@ -1,57 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.4
4
+ version: 0.13.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Liaw
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-06 00:00:00.000000000 Z
11
+ date: 2023-09-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: teLogger
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '0.2'
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: '0'
26
+ version: '0.2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: toolrack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: gvcs
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
31
+ - - ">"
46
32
  - !ruby/object:Gem::Version
47
- version: '0'
33
+ version: '0.23'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - ">="
38
+ - - ">"
53
39
  - !ruby/object:Gem::Version
54
- version: '0'
40
+ version: '0.23'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: ptools
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -67,21 +53,7 @@ dependencies:
67
53
  - !ruby/object:Gem::Version
68
54
  version: 1.4.0
69
55
  - !ruby/object:Gem::Dependency
70
- name: devops_assist
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: gem-release
56
+ name: rspec
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
59
  - - ">="
@@ -168,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
140
  - !ruby/object:Gem::Version
169
141
  version: '0'
170
142
  requirements: []
171
- rubygems_version: 3.4.10
143
+ rubygems_version: 3.4.6
172
144
  signing_key:
173
145
  specification_version: 4
174
146
  summary: GIT command line interface