git_repo_upgrader 0.0.5 → 0.0.7

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: 6dc30508c2560223be1a5e778a2e89b4c85a392389006fb12568fea28649c853
4
- data.tar.gz: 25e5520bd62ae4d477a9e47d7fa1f7157b72053386a0cd8aa165cb350096d16e
3
+ metadata.gz: 9dc4cb2cb119aeb8d1b096ec3a88f26fd669f26a074a105e5961dff3d62d875a
4
+ data.tar.gz: 411d906824438dd973f43539aa64358e1fa9cb4bfc4d53b7954a5074f9da7ca0
5
5
  SHA512:
6
- metadata.gz: bf2d26c5199607e71d6a7d73e17aabc4b06ef4a2d22911942c9b66e53cc6927d0a23470b24d987d49c86642114277321fa32d1cb867618019c548d3a7c90e899
7
- data.tar.gz: e2799174277e2ff287bea48274ed671924301efbd16afa074522d44c1bc0facda1313698b3a7b83e721cc47c916aac81820fdc0bbdf3730e4ce9e9ecad3368b4
6
+ metadata.gz: de6ae723180bb226c7f610a2378b8609a4c89390a5fdd7a824cbe95aa99372012d68ea3827f9777d9105e1592316105c4987211cf83aabdf9e7dae7001a36cda
7
+ data.tar.gz: 19b772a4dacaf70bf231b3a5961047c02929be01ee9614167051e3c7c1c5e6031c0d9a83e20a79756b0f5ce84da6a93e23e190736b3129300dde449a6515e9c8
data/README.md CHANGED
@@ -1,9 +1,16 @@
1
1
  # git_repo_upgrader
2
+ [![Gem](https://img.shields.io/gem/v/git_repo_upgrader?_color=default&style=plastic&logo=ruby&logoColor=red)](https://rubygems.org/gems/git_repo_upgrader)
3
+ ![downloads](https://img.shields.io/gem/dt/git_repo_upgrader?color=blue&style=plastic)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-gold.svg?style=plastic&logo=mit)](LICENSE)
2
5
 
3
- Copy specific files from another git repository into your current project and provide (optional) automatic commits.
6
+ > Copy specific files from another git repository into your current project and provide (optional) automatic commits.
4
7
 
5
8
  Useful for manually integrated files from another git project. Do upgrades by one command.
6
9
 
10
+ ```diff
11
+ - early version, not to be meant for production use
12
+ ```
13
+
7
14
  # Contents
8
15
 
9
16
  * [Installation](#installation)
@@ -50,7 +57,7 @@ TODO
50
57
 
51
58
  At best create a new rake task containing a options hash and then run #upgrade.
52
59
 
53
- See the examples below for option hahes.
60
+ See the examples below for option hashes.
54
61
 
55
62
  ### Examples
56
63
 
@@ -67,7 +74,8 @@ See the examples below for option hahes.
67
74
  'dist/app.bundle.css' => 'web/js/lib/project/app.bundle.css',
68
75
  # copy a whole directory recursively
69
76
  'dist/img' => 'web/js/lib/project/img',
70
- }
77
+ },
78
+ commit: 'prompt' # 'prompt' by default, other options: 'false','auto'
71
79
  }
72
80
  GitRepoUpgrader.upgrade options
73
81
  ```
@@ -1,3 +1,3 @@
1
1
  module GitRepoUpgrader
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.7'.freeze
3
3
  end
@@ -23,7 +23,8 @@ require 'git_repo_upgrader/version'
23
23
  # 'dist/app.bundle.css' => 'web/js/lib/project/app.bundle.css',
24
24
  # # copy a whole directory recursively
25
25
  # 'dist/img' => 'web/js/lib/project/img',
26
- # }
26
+ # },
27
+ # commit: 'false'
27
28
  # }
28
29
  # GitRepoUpgrader.upgrade options
29
30
  #
@@ -36,15 +37,22 @@ module GitRepoUpgrader
36
37
  GIT_REPO_NAME_REGEX = /\/([^\/]+).git/
37
38
 
38
39
  # @param [Hash] options
40
+ # @param [Hash] options.repo
41
+ # @param [String] options.repo.uri
42
+ # @param [String] options.repo.branch
43
+ # @param [Hash<String,String>] options.files_to_copy <src,destination>
44
+ # @param ['auto','skip','prompt'] options.commit='prompt'
39
45
  def self.upgrade(options)
40
46
  puts '*****************************'.yellow
41
- puts '** Git Repo Upgrader'.yellow
47
+ puts "** Git Repo Upgrader #{GitRepoUpgrader::VERSION}".yellow
42
48
  puts '*****************************'.yellow
43
49
  repo_dir, tmp_dir = _checkout_git_repo options[:repo][:uri], options[:repo][:branch]
44
50
  _copy_files_from_checkout repo_dir, options[:files_to_copy]
45
51
  _cleanup_checkout tmp_dir
46
52
  repo_name = options[:repo][:uri].match(GIT_REPO_NAME_REGEX)[1]
47
- _commit_files options[:files_to_copy], repo_name
53
+ if options[:commit] != false && options[:commit] != 'false' && options[:commit] != 'skip'
54
+ _commit_files options[:files_to_copy], repo_name, type: options[:commit]
55
+ end
48
56
  puts
49
57
  puts "Everything done, be happy! :-) ".magenta
50
58
  end
@@ -52,7 +60,7 @@ module GitRepoUpgrader
52
60
  private
53
61
 
54
62
  # @param [String] github source path
55
- # @param [String] branch
63
+ # @param [String] branch='master'
56
64
  # @return [String] path to repo dir
57
65
  def self._checkout_git_repo(source, branch)
58
66
  print ' - creating tmp dir ... '
@@ -62,12 +70,13 @@ module GitRepoUpgrader
62
70
  print tmp_dirname + ' ... '
63
71
  Dir.chdir tmp_dirname
64
72
  puts 'done'.green
73
+ branch = 'master' unless branch
65
74
  begin
66
- puts ' - checkoutA repository ' + source + " (#{branch}) ... "
75
+ puts ' - checkout repository ' + source + " (#{branch}) ... "
67
76
  git_command = "git clone --single-branch --branch #{branch} #{source}"
68
77
  puts ' ' + git_command.blue
69
78
  git_result = system(git_command)
70
- raise "invalid username or password" unless git_result
79
+ raise "Error occurred while trying to clone the repository. Check messages before. Invalid username or password?" unless git_result
71
80
  rescue RuntimeError => e
72
81
  puts e.to_s.red
73
82
  retry
@@ -78,7 +87,6 @@ module GitRepoUpgrader
78
87
  [File.expand_path(repo_dir), tmp_dirname]
79
88
  end
80
89
 
81
-
82
90
  def self._copy_files_from_checkout(repo_dir, files_to_copy)
83
91
  Dir.chdir repo_dir
84
92
  puts ' - copy repo files ... '
@@ -101,21 +109,24 @@ module GitRepoUpgrader
101
109
  puts 'done'.green
102
110
  end
103
111
 
104
- def self._commit_files(files, repo_name)
105
- puts
106
- default_input = 'y'
112
+ # @param ['prompt','auto','skip'] type
113
+ def self._commit_files(files, repo_name, type: 'prompt')
107
114
  yes_no = nil
108
- loop do
109
- print "Commit the copied files above? (y/n) [#{default_input}]:".yellow
110
- yes_no = STDIN.gets.chomp
111
- yes_no = default_input if yes_no == ''
112
- if yes_no == '' || !(['y', 'n'].include? yes_no)
113
- puts "Invalid option '#{yes_no}'".red
114
- else
115
- break
115
+ if type == 'prompt'
116
+ puts
117
+ default_input = 'y'
118
+ loop do
119
+ print "Commit the copied files above? (y/n) [#{default_input}]:".yellow
120
+ yes_no = STDIN.gets.chomp
121
+ yes_no = default_input if yes_no == ''
122
+ if yes_no == '' || !(['y', 'n'].include? yes_no)
123
+ puts "Invalid option '#{yes_no}'".red
124
+ else
125
+ break
126
+ end
116
127
  end
117
128
  end
118
- if yes_no == 'y'
129
+ if yes_no == 'y' || type == 'auto'
119
130
  Dir.chdir PROJECT_DIR
120
131
  # add
121
132
  git_commit_command1 = %Q(git add "#{files.values.join('" "')}")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_repo_upgrader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthäus J. N. Beyrle
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-14 00:00:00.000000000 Z
11
+ date: 2023-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -119,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  - !ruby/object:Gem::Version
120
120
  version: '0'
121
121
  requirements: []
122
- rubygems_version: 3.0.8
122
+ rubygems_version: 3.1.4
123
123
  signing_key:
124
124
  specification_version: 4
125
125
  summary: Copy specific files from another git repo by one command