extract-repo 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +8 -0
  3. data/boot/start.rb +1 -1
  4. data/lib/extract_repo.rb +35 -11
  5. metadata +11 -11
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 557339120e6b4827fe0283731b74abf3466ca706a376496aacab6bfdfd004b52
4
- data.tar.gz: e29e7133f566f40cf7637f0017ad68fd091079dd0f8635832f20beacfb3a5c58
3
+ metadata.gz: 8d5ea6956dc3a02f797894c47d0eaea989ce46d0dcaa355c5e16ef0111719b88
4
+ data.tar.gz: c03ba66bd8348e32dc8bdc1dc35fd2adb60e9914b87207af01481b2585a54adf
5
5
  SHA512:
6
- metadata.gz: 37fedadcff384c41c447b2cd2a28cd7ca4da621978899d01c8859b9db4ce758ed600b410bd0609c9b626551367143d0d913e28bf789174d93e2195174d97e6a7
7
- data.tar.gz: 702b4446a2b45d8ec36c903669131192fab9c7358c3af66388c302c223acaf8b32ca50c6e1c1c17fede64db726767a64245cd71f881861f3b4026c2ad96c97a5
6
+ metadata.gz: 68931f1e4f076a9f2f810b78725092f05b97748c5a602c4d07174350dcd3dc69090b2525f134c55426b50c8e284a1cc3ae28f0497746a0d9019718b80c98579b
7
+ data.tar.gz: 554b2bc2b3cfa2de1568d7b581f630b9445431c30159bc8c6ccc6b6975fb624dcca937600f56455cdf79607d5740a07f527b06e34a2052d79783b97d6f9e8635
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.0.11] - 2025-04-23
2
+
3
+ - Fix problem that was including irrelevant file renames in the final git history
4
+
5
+ ## [0.0.10] - 2025-04-15
6
+
7
+ - Remove pry as a required dependency
8
+
1
9
  ## [0.0.9] - 2025-01-07
2
10
 
3
11
  - Bump Ruby to 3.4.1
data/boot/start.rb CHANGED
@@ -7,7 +7,7 @@ if File.exist?("#{__dir__}/../Gemfile")
7
7
  require "bundler/setup"
8
8
  end
9
9
 
10
- if ENV["FOOBARA_ENV"] == "development" || ENV["FOOBARA_ENV"] == "test"
10
+ if %w[development test].include?(ENV["FOOBARA_ENV"])
11
11
  require "pry"
12
12
  require "pry-byebug"
13
13
  end
data/lib/extract_repo.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "pry"
2
1
  require "uri"
3
2
  require "English"
4
3
 
@@ -6,11 +5,14 @@ require "foobara/all"
6
5
 
7
6
  # TODO: allow extracting from a local repo and default to that repo as "."
8
7
  class ExtractRepo < Foobara::Command
8
+ description "Extracts directories/files of your choosing from one repo to another"
9
+
9
10
  inputs do
10
- repo_url :string, :required
11
- paths [:string], :required
12
- output_path :string, default: "#{Dir.home}/tmp/extract"
13
- delete_extracted :boolean, default: false
11
+ repo_url_or_path :string, :required, "The source repository to extract from. Can be a URL or a local directory"
12
+ paths [:string], :required, "Paths to each directory/file to extract"
13
+ output_path :string, default: "#{Dir.home}/tmp/extract",
14
+ description: "Where to create a new repo and move the extracted files to"
15
+ delete_extracted :boolean, default: false, description: "Delete the extracted files from the source repository"
14
16
  end
15
17
 
16
18
  attr_accessor :file_paths, :absolute_repo_path
@@ -33,9 +35,9 @@ class ExtractRepo < Foobara::Command
33
35
 
34
36
  def determine_absolute_repo_path
35
37
  self.absolute_repo_path = if local_repository?
36
- File.absolute_path(repo_url)
38
+ File.absolute_path(repo_url_or_path)
37
39
  else
38
- repo_url
40
+ repo_url_or_path
39
41
  end
40
42
  end
41
43
 
@@ -56,7 +58,7 @@ class ExtractRepo < Foobara::Command
56
58
  end
57
59
 
58
60
  def local_repository?
59
- !URI.parse(repo_url).scheme
61
+ !URI.parse(repo_url_or_path).scheme
60
62
  end
61
63
 
62
64
  def remove_origin
@@ -114,10 +116,32 @@ class ExtractRepo < Foobara::Command
114
116
  def determine_historic_paths
115
117
  chdir output_path do
116
118
  file_paths.dup.each do |file_path|
117
- historic_paths = sh "git log --follow --name-only --pretty=format: -- \"#{file_path}\""
119
+ renames = {}
120
+
121
+ relevant_sha1s = sh "git log --follow --pretty=format:%H -- \"#{file_path}\""
122
+ relevant_sha1s = relevant_sha1s.strip.split("\n")
123
+
124
+ relevant_sha1s.each do |sha1|
125
+ status_lines = sh "git diff-tree -M --no-commit-id --name-status -r #{sha1}"
126
+ status_lines = status_lines.strip.split("\n")
127
+
128
+ status_lines.each do |status_line|
129
+ next unless status_line.start_with?("R")
130
+
131
+ similarity, from_path, to_path = status_line.split("\t")
132
+ similarity = similarity.match(/^R0*(\d+)$/)[1].to_i
133
+
134
+ if similarity >= 80
135
+ renames[to_path] = from_path
136
+ end
137
+ end
138
+ end
139
+
140
+ loop do
141
+ file_path = renames[file_path]
142
+ break unless file_path
118
143
 
119
- historic_paths.split("\n").each do |historic_path|
120
- file_paths << historic_path
144
+ file_paths << file_path
121
145
  end
122
146
  end
123
147
  end
metadata CHANGED
@@ -1,42 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: extract-repo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-07 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: foobara
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - ">="
16
+ - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '0'
18
+ version: 0.0.102
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - ">="
23
+ - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '0'
25
+ version: 0.0.102
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: foobara-sh-cli-connector
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - ">="
30
+ - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '0'
32
+ version: 0.0.1
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ">="
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '0'
39
+ version: 0.0.1
40
40
  email:
41
41
  - azimux@gmail.com
42
42
  executables:
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  - !ruby/object:Gem::Version
78
78
  version: '0'
79
79
  requirements: []
80
- rubygems_version: 3.6.2
80
+ rubygems_version: 3.6.8
81
81
  specification_version: 4
82
82
  summary: Extract code from one repository into a new repository, preserving history
83
83
  of the extracted files.