extract-repo 0.0.1 → 0.0.3

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: df2cb9436512b834122784a9c5adf30866f0a7b946b9db8472a00364a71bf5c4
4
- data.tar.gz: 6090bee17c862869a81133d227f089d7f3204334218c9670d375770378b626f4
3
+ metadata.gz: d9fd3a3ce2f14da2877eb2121751d1ac1b4ee3fe99638076d68ede350d2d7916
4
+ data.tar.gz: da8ea55545f812e170b0e1d35b3473e4358224c3b0cd49dbca2d82aad2ee24b9
5
5
  SHA512:
6
- metadata.gz: '049fc4d25cc27d4407e5e8e0c12b240dc367a89e334757cb7c3bd22da8620145857fd578ec738daf1f43e25b089e3216f7cd8e5c462a81e53aacb41a1fabf4da'
7
- data.tar.gz: 7bf363de1bc88d5b2ba4213526190ebf1ee60950b3bda47e2945ea4db2477bfa04901d9ea9bdfe733b98d7f1f8ef7697c44c4dcd416dc6a3c5cd88f5fdfe744b
6
+ metadata.gz: 979ad101bcdd4089c5907f5eb5274d73acaafd13e0c327d68531f44e4b2384d310e78f9f235fab8eb4cab1f6f1335a63c035f7c7cae10cc5eea619e0f82d5d40
7
+ data.tar.gz: 6851d37168a3028add2b25b08ec112e2fb92330a799894ed1fdb582eb8b49d251c2ae215af6a48e2ba846668c3c92c663ca9ca42aafcba498f9c3461ec8dcf0e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [0.0.3] - 2024-08-25
2
+
3
+ - Make use of CommandConnector
4
+ - Support deleting extracted paths
5
+
6
+ ## [0.0.2] - 2024-08-25
7
+
8
+ - Include extract-repo executable
9
+
1
10
  ## [0.0.1] - 2024-08-25
2
11
 
3
12
  - Initial release
data/bin/extract-repo ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative "../boot"
4
+
5
+ require "foobara/sh_cli_connector"
6
+
7
+ command_connector = Foobara::CommandConnectors::ShCliConnector.new(single_command_mode: true)
8
+
9
+ command_connector.connect(ExtractRepo)
10
+
11
+ command_connector.run(ARGV)
data/lib/extract_repo.rb CHANGED
@@ -2,16 +2,19 @@ require "pry"
2
2
  require "English"
3
3
  require "foobara/all"
4
4
 
5
+ # TODO: allow extracting from a local repo and default to that repo as "."
5
6
  class ExtractRepo < Foobara::Command
6
7
  inputs do
7
8
  repo_url :string, :required
8
9
  paths [:string], :required
9
- output_path :string, default: "/#{Dir.home}/tmp/extract"
10
+ output_path :string, default: "#{Dir.home}/tmp/extract"
11
+ delete_extracted :boolean, default: false
10
12
  end
11
13
 
12
- attr_accessor :file_paths
14
+ attr_accessor :file_paths, :absolute_repo_path
13
15
 
14
16
  def execute
17
+ determine_absolute_repo_path
15
18
  mk_extract_dir
16
19
  rm_old_repo
17
20
 
@@ -22,6 +25,16 @@ class ExtractRepo < Foobara::Command
22
25
  determine_historic_paths
23
26
  filter_repo
24
27
  remove_replaces
28
+
29
+ delete_extracted_paths if delete_extracted?
30
+ end
31
+
32
+ def determine_absolute_repo_path
33
+ self.absolute_repo_path = if local_repository?
34
+ File.absolute_path(repo_url)
35
+ else
36
+ repo_url
37
+ end
25
38
  end
26
39
 
27
40
  def chdir(dir, &)
@@ -46,10 +59,14 @@ class ExtractRepo < Foobara::Command
46
59
 
47
60
  def clone_repo
48
61
  chdir output_path do
49
- sh "git clone #{repo_url}"
62
+ sh "git clone #{absolute_repo_path}"
50
63
  end
51
64
  end
52
65
 
66
+ def local_repository?
67
+ !URI.parse(repo_url).scheme
68
+ end
69
+
53
70
  def remove_origin
54
71
  chdir repo_dir do
55
72
  sh "git remote rm origin"
@@ -67,7 +84,10 @@ class ExtractRepo < Foobara::Command
67
84
  replace_sha1s = sh "git replace -l", silent: true
68
85
  replace_sha1s = replace_sha1s.chomp.split("\n")
69
86
  replace_sha1s.each do |replace_sha1|
87
+ # It seems like some versions of git do not create replace markers when doing this
88
+ # :nocov:
70
89
  sh "git replace -d #{replace_sha1}"
90
+ # :nocov:
71
91
  end
72
92
  end
73
93
  end
@@ -128,6 +148,21 @@ class ExtractRepo < Foobara::Command
128
148
  end
129
149
  end
130
150
 
151
+ # This feels dangerous however it is opt-in at least
152
+ def delete_extracted_paths
153
+ return unless local_repository?
154
+
155
+ Dir.chdir absolute_repo_path do
156
+ paths.each do |path|
157
+ FileUtils.rm_r path
158
+ end
159
+ end
160
+ end
161
+
162
+ def delete_extracted?
163
+ delete_extracted
164
+ end
165
+
131
166
  def sh(cmd, dry_run: false, silent: false)
132
167
  unless silent
133
168
  puts cmd
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extract-repo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-25 00:00:00.000000000 Z
11
+ date: 2024-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: foobara
@@ -24,10 +24,25 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
- description:
27
+ - !ruby/object:Gem::Dependency
28
+ name: foobara-sh-cli-connector
29
+ requirement: !ruby/object:Gem::Requirement
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
+ description:
28
42
  email:
29
43
  - azimux@gmail.com
30
- executables: []
44
+ executables:
45
+ - extract-repo
31
46
  extensions: []
32
47
  extra_rdoc_files: []
33
48
  files:
@@ -36,6 +51,7 @@ files:
36
51
  - LICENSE-MIT.txt
37
52
  - LICENSE.txt
38
53
  - README.md
54
+ - bin/extract-repo
39
55
  - lib/extract_repo.rb
40
56
  homepage: https://github.com/foobara/extract-repo
41
57
  licenses:
@@ -46,7 +62,7 @@ metadata:
46
62
  source_code_uri: https://github.com/foobara/extract-repo
47
63
  changelog_uri: https://github.com/foobara/extract-repo/blob/main/CHANGELOG.md
48
64
  rubygems_mfa_required: 'true'
49
- post_install_message:
65
+ post_install_message:
50
66
  rdoc_options: []
51
67
  require_paths:
52
68
  - lib
@@ -61,8 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
61
77
  - !ruby/object:Gem::Version
62
78
  version: '0'
63
79
  requirements: []
64
- rubygems_version: 3.4.10
65
- signing_key:
80
+ rubygems_version: 3.5.18
81
+ signing_key:
66
82
  specification_version: 4
67
83
  summary: Extract code from one repository into a new repository, preserving history
68
84
  of the extracted files.