git_repo_upgrader 0.0.4 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -3
- data/lib/git_repo_upgrader/version.rb +1 -1
- data/lib/git_repo_upgrader.rb +33 -20
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dc4cb2cb119aeb8d1b096ec3a88f26fd669f26a074a105e5961dff3d62d875a
|
4
|
+
data.tar.gz: 411d906824438dd973f43539aa64358e1fa9cb4bfc4d53b7954a5074f9da7ca0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
```
|
data/lib/git_repo_upgrader.rb
CHANGED
@@ -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
|
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
|
-
|
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 ' -
|
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 "
|
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 ... '
|
@@ -87,7 +95,9 @@ module GitRepoUpgrader
|
|
87
95
|
final_dest = PROJECT_DIR + '/' + dest
|
88
96
|
# remove last folder from path, because FileUtils.cp_r creates the last folder in dest implicitly
|
89
97
|
final_dest = final_dest[0...-1] if final_dest.end_with? '/' # cut / at the end if available
|
90
|
-
|
98
|
+
if (File.basename(source) == File.basename(dest))
|
99
|
+
final_dest = Pathname(final_dest).dirname.to_s # cut last folder if identical names are used to avoid duplicates
|
100
|
+
end
|
91
101
|
FileUtils.cp_r(repo_dir + '/' + source, final_dest)
|
92
102
|
end
|
93
103
|
end
|
@@ -99,21 +109,24 @@ module GitRepoUpgrader
|
|
99
109
|
puts 'done'.green
|
100
110
|
end
|
101
111
|
|
102
|
-
|
103
|
-
|
104
|
-
default_input = 'y'
|
112
|
+
# @param ['prompt','auto','skip'] type
|
113
|
+
def self._commit_files(files, repo_name, type: 'prompt')
|
105
114
|
yes_no = nil
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
114
127
|
end
|
115
128
|
end
|
116
|
-
if yes_no == 'y'
|
129
|
+
if yes_no == 'y' || type == 'auto'
|
117
130
|
Dir.chdir PROJECT_DIR
|
118
131
|
# add
|
119
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.
|
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:
|
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.
|
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
|