Skip to content

Commit aa55f32

Browse files
committed
Auto clone repos
1 parent b22465e commit aa55f32

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## [Unreleased]
22

33
- Display progress
4+
- Automatically clone repo to tmp dir if repo is not a local directory
45

56
## [0.3.1] 2025-03-14
67

lib/octostat/git.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require "open3"
2+
require "tmpdir"
23

34
module Octostat
45
class Git
@@ -17,9 +18,10 @@ class Git
1718

1819
LIST_COMMAND = ["git", "log", "--pretty=format:#{LOG_FORMAT}"]
1920
COUNT_COMMAND = ["git", "rev-list", "--count", "HEAD"]
21+
CLONE_COMMAND = ["git", "clone"]
2022

2123
def initialize path
22-
@path = path
24+
@path = Dir.exist?(path) ? path : clone_repo(path)
2325
end
2426

2527
def env
@@ -51,6 +53,12 @@ def each
5153

5254
private
5355

56+
def clone_repo upstream
57+
repo_path = Dir.mktmpdir
58+
Open3.capture2(*CLONE_COMMAND, upstream, repo_path)
59+
repo_path
60+
end
61+
5462
attr_reader :path
5563
end
5664
end

test/git_test.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ def test_count
3636
git = Octostat::Git.new(@repo_path)
3737
assert_equal 7, git.count
3838
end
39+
40+
def test_clone_repo_if_remote
41+
@repo_path = "https://github.com/testdouble/octostat"
42+
git = Octostat::Git.new(@repo_path)
43+
assert git.count > 0
44+
end
3945
end

0 commit comments

Comments
 (0)