ruby_workspace_manager 0.2.0 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e8c287aa2d28cf7ed4c21f9ce567eb25f5a2164e0d064619aa2110676461ae0
4
- data.tar.gz: b2d3ca1d17eecdf4b9233469bdaf24c4f43a9d7ec3cb6bd99fdb9fb2a527b419
3
+ metadata.gz: fbe69d99300fafa6359944aa4a1cb16a3ed9cbb0e1e544b3a428a4e04af4dc66
4
+ data.tar.gz: 114e54d2ac5872ae866ecf0503b8ebdeb9c72b0db892a564e0b3889b4ff1e0fd
5
5
  SHA512:
6
- metadata.gz: 9b1c5e6dac68401d8ec61e70323af0bea421370354a5bfa36d66917bcd08222026b9ac535e800c1aa5f8405ffde6759381c53fecea629972f799e42e1176f4b2
7
- data.tar.gz: a535d8642e4c5c3736a4606954e4a21a2d32e8926293d89ca2622fc3c8c0ced4b3667e0d5375b51c5b23cece660d76b1aa9e062cf270d73c001977b2e4a5ab7d
6
+ metadata.gz: bad333bc09182d824ef4c5b4e50fc290a7922e81a8e616a991d54cf994cca8340038fc5bb4b2dfa1612292ac7fc3f6008089ea6ff7a95b702ef65c0335ee97b4
7
+ data.tar.gz: bdfb899d956de2f9aa4d694d83b74cd79cb9936c0f38cfa1f64c78931846436be644510e0fce9dcfb8774af61b74d5cc24e09769aa0b2547c6a9ffba45d1dc95
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "open3"
4
+
3
5
  module Rwm
4
6
  class AffectedDetector
5
7
  attr_reader :workspace, :graph, :base_branch
@@ -41,16 +43,22 @@ module Rwm
41
43
 
42
44
  def detect_base_branch
43
45
  # Try to read the remote's default branch
44
- ref = `git -C #{workspace.root} symbolic-ref refs/remotes/origin/HEAD 2>/dev/null`.chomp
45
- unless ref.empty?
46
- # refs/remotes/origin/main → main
47
- return ref.sub(%r{^refs/remotes/origin/}, "")
46
+ ref, _, status = Open3.capture3("git", "-C", workspace.root, "symbolic-ref", "refs/remotes/origin/HEAD")
47
+ if status.success?
48
+ ref = ref.chomp
49
+ unless ref.empty?
50
+ # refs/remotes/origin/main → main
51
+ return ref.sub(%r{^refs/remotes/origin/}, "")
52
+ end
48
53
  end
49
54
 
50
55
  # Fall back: check if main or master exists
51
- branches = `git -C #{workspace.root} branch --list main master 2>/dev/null`.lines.map(&:strip)
52
- return "main" if branches.include?("main")
53
- return "master" if branches.include?("master")
56
+ out, _, status = Open3.capture3("git", "-C", workspace.root, "branch", "--list", "main", "master")
57
+ if status.success?
58
+ branches = out.lines.map(&:strip)
59
+ return "main" if branches.include?("main")
60
+ return "master" if branches.include?("master")
61
+ end
54
62
 
55
63
  # Last resort
56
64
  "main"
@@ -60,17 +68,17 @@ module Rwm
60
68
  files = Set.new
61
69
 
62
70
  # 1. Committed changes: base branch vs HEAD
63
- committed = `git -C #{workspace.root} diff --name-only #{base_branch}...HEAD 2>/dev/null`.chomp
64
- committed.lines.each { |l| files << l.chomp }
71
+ committed, _, status = Open3.capture3("git", "-C", workspace.root, "diff", "--name-only", "#{base_branch}...HEAD")
72
+ committed.lines.each { |l| files << l.chomp } if status.success?
65
73
 
66
74
  unless @committed_only
67
75
  # 2. Staged changes (not yet committed)
68
- staged = `git -C #{workspace.root} diff --name-only --cached 2>/dev/null`.chomp
69
- staged.lines.each { |l| files << l.chomp }
76
+ staged, _, status = Open3.capture3("git", "-C", workspace.root, "diff", "--name-only", "--cached")
77
+ staged.lines.each { |l| files << l.chomp } if status.success?
70
78
 
71
79
  # 3. Unstaged working directory changes
72
- unstaged = `git -C #{workspace.root} diff --name-only 2>/dev/null`.chomp
73
- unstaged.lines.each { |l| files << l.chomp }
80
+ unstaged, _, status = Open3.capture3("git", "-C", workspace.root, "diff", "--name-only")
81
+ unstaged.lines.each { |l| files << l.chomp } if status.success?
74
82
  end
75
83
 
76
84
  files.reject(&:empty?).to_a
data/lib/rwm/cli.rb CHANGED
@@ -40,6 +40,8 @@ module Rwm
40
40
  return 0
41
41
  end
42
42
 
43
+ check_required_tools
44
+
43
45
  # Expand task shortcuts: `rwm test` → `rwm run test`
44
46
  if TASK_SHORTCUTS.include?(command_name)
45
47
  @argv.unshift(command_name)
@@ -64,6 +66,15 @@ module Rwm
64
66
 
65
67
  private
66
68
 
69
+ def check_required_tools
70
+ %w[git bundle].each do |tool|
71
+ unless system("which", tool, out: File::NULL, err: File::NULL)
72
+ $stderr.puts "Error: #{tool} is not installed or not in PATH."
73
+ exit 1
74
+ end
75
+ end
76
+ end
77
+
67
78
  def print_help
68
79
  puts <<~HELP
69
80
  rwm #{Rwm::VERSION} — Ruby Workspace Manager
data/lib/rwm/gemfile.rb CHANGED
@@ -12,12 +12,16 @@
12
12
  # rwm_lib "auth"
13
13
 
14
14
  require "bundler"
15
+ require "open3"
15
16
 
16
17
  module Rwm
17
18
  module GemfileDsl
18
19
  def rwm_workspace_root
19
- @rwm_workspace_root ||= `git rev-parse --show-toplevel 2>/dev/null`.strip.tap do |root|
20
+ @rwm_workspace_root ||= begin
21
+ out, _, status = Open3.capture3("git", "rev-parse", "--show-toplevel")
22
+ root = status.success? ? out.strip : ""
20
23
  raise "rwm: not inside a git repository" if root.empty?
24
+ root
21
25
  end
22
26
  end
23
27
 
@@ -3,7 +3,7 @@
3
3
  require "digest"
4
4
  require "fileutils"
5
5
  require "json"
6
- require "shellwords"
6
+ require "open3"
7
7
 
8
8
  module Rwm
9
9
  class TaskCache
@@ -63,12 +63,12 @@ module Rwm
63
63
  digest.update(File.read(file))
64
64
  end
65
65
 
66
- # Include dependency content hashes (transitive invalidation)
66
+ # Include dependency content hashes (transitive invalidation).
67
+ # If a dependency is missing, let it raise — a stale graph should
68
+ # not silently produce incorrect cache hits.
67
69
  @graph.dependencies(package.name).sort.each do |dep_name|
68
70
  dep_pkg = @workspace.find_package(dep_name)
69
71
  digest.update(content_hash(dep_pkg))
70
- rescue PackageNotFoundError
71
- next
72
72
  end
73
73
 
74
74
  @content_hashes[package.name] = digest.hexdigest
@@ -78,8 +78,8 @@ module Rwm
78
78
  def cache_declarations(package)
79
79
  return @cache_declarations[package.name] if @cache_declarations.key?(package.name)
80
80
 
81
- output = `cd #{Shellwords.escape(package.path)} && bundle exec rake rwm:cache_config 2>/dev/null`
82
- @cache_declarations[package.name] = if $?.success? && !output.strip.empty?
81
+ output, _, status = Open3.capture3("bundle", "exec", "rake", "rwm:cache_config", chdir: package.path)
82
+ @cache_declarations[package.name] = if status.success? && !output.strip.empty?
83
83
  JSON.parse(output.strip)
84
84
  else
85
85
  {}
data/lib/rwm/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Rwm
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/rwm/workspace.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "open3"
4
+
3
5
  module Rwm
4
6
  class Workspace
5
7
  RWM_DIR = ".rwm"
@@ -15,7 +17,8 @@ module Rwm
15
17
  # Find the workspace root via git
16
18
  def self.find(start_dir = Dir.pwd)
17
19
  dir = File.expand_path(start_dir)
18
- git_root = `git -C #{dir} rev-parse --show-toplevel 2>/dev/null`.chomp
20
+ git_root, _, status = Open3.capture3("git", "-C", dir, "rev-parse", "--show-toplevel")
21
+ git_root = status.success? ? git_root.chomp : ""
19
22
 
20
23
  raise WorkspaceNotFoundError if git_root.empty?
21
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_workspace_manager
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Siddharth Bhatt