extract-repo 0.0.2 → 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: 8cf628311b36cf927236447e3315c398ce47e426531863f1020f1b2c389eae09
4
- data.tar.gz: c503d864066e0a991d7526e5f465676b3d1bbcaef30d00ee21fe96ece6e894dd
3
+ metadata.gz: d9fd3a3ce2f14da2877eb2121751d1ac1b4ee3fe99638076d68ede350d2d7916
4
+ data.tar.gz: da8ea55545f812e170b0e1d35b3473e4358224c3b0cd49dbca2d82aad2ee24b9
5
5
  SHA512:
6
- metadata.gz: 3ed45d4ca3957bc08da53b939a56d196f85b26eb6d88d941c2110d8239ae80db446a05c2a4914224670a3c22e3647d46d4eca647adcd8bbb1db311367a7f1a31
7
- data.tar.gz: a5d42d46f41aee15bf9e07e4c682642a4cb24e7e4da43f117f67da2b4aea2868d73f1430c5a07cb5cd2a9cf458a853744b0e0834679fa9ff212103fb12dce639
6
+ metadata.gz: 979ad101bcdd4089c5907f5eb5274d73acaafd13e0c327d68531f44e4b2384d310e78f9f235fab8eb4cab1f6f1335a63c035f7c7cae10cc5eea619e0f82d5d40
7
+ data.tar.gz: 6851d37168a3028add2b25b08ec112e2fb92330a799894ed1fdb582eb8b49d251c2ae215af6a48e2ba846668c3c92c663ca9ca42aafcba498f9c3461ec8dcf0e
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## [0.0.3] - 2024-08-25
2
+
3
+ - Make use of CommandConnector
4
+ - Support deleting extracted paths
5
+
1
6
  ## [0.0.2] - 2024-08-25
2
7
 
3
8
  - Include extract-repo executable
data/bin/extract-repo CHANGED
@@ -1,6 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require_relative "../lib/extract_repo"
3
+ require_relative "../boot"
4
4
 
5
- repo_url, *paths = ARGV
6
- ExtractRepo.run!(repo_url:, paths:)
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.2
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,7 +24,21 @@ 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
44
  executables:
@@ -48,7 +62,7 @@ metadata:
48
62
  source_code_uri: https://github.com/foobara/extract-repo
49
63
  changelog_uri: https://github.com/foobara/extract-repo/blob/main/CHANGELOG.md
50
64
  rubygems_mfa_required: 'true'
51
- post_install_message:
65
+ post_install_message:
52
66
  rdoc_options: []
53
67
  require_paths:
54
68
  - lib
@@ -63,8 +77,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
77
  - !ruby/object:Gem::Version
64
78
  version: '0'
65
79
  requirements: []
66
- rubygems_version: 3.4.10
67
- signing_key:
80
+ rubygems_version: 3.5.18
81
+ signing_key:
68
82
  specification_version: 4
69
83
  summary: Extract code from one repository into a new repository, preserving history
70
84
  of the extracted files.