ruby_git 0.1.3 → 0.2.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: 32a1bc5ee8f2d70f5a30eb7fda1c65f0072b59d1a3ad5e46713ba51d1de141fb
4
- data.tar.gz: 6456bd376f470100e27d273066a3a3376e9e3565b85d2cd83cc9ebd1aabe88e7
3
+ metadata.gz: 740fbc545a60561d555d5d698dc6303d150a7fa4eed583afbf70facd70610502
4
+ data.tar.gz: '094fb5b8d53b28c240074f6c874fddaf503f2a5f4218207a437205c0aec4118e'
5
5
  SHA512:
6
- metadata.gz: db1a608c224aa0ad445bc63ab48872465ea3bbd8310d9e4cda2b9f1bceeb5e2c8597272144c90792d42ce4737f20d4a640659ee7d55e3ef983c2746cf5f05141
7
- data.tar.gz: 39ce71a07fc6690de087e695be7e10723d80f033d3c3b6d2b8a0a4c11b280b78c85a50c435bdbb209d2c5eb5f2e1e9a2eb57632e1ffc431ada792b691e37f560
6
+ metadata.gz: 8be9d5931ea2c500fc07f0f2b0fcb93e7324e8bb156216c0f6adf147c465a41b97e6b1e3f159fe5cae5ff804613eb82b18f4ca7ea41abf4a0d4a5fb34a098444
7
+ data.tar.gz: d054d7dca124d1da739dab1d7191d81dd2f7ceef900b81b118ad18f0bad2f852eda4d1970da2c169a3f18857e4d804a1efb48ac9fb7fb5b08ba4e592276741bf
@@ -12,7 +12,7 @@ AllCops:
12
12
  Layout/LineLength:
13
13
  Max: 120
14
14
 
15
- # The DSL for RSpec and the gemspec file make it very hard to limit block length:
15
+ # The DSL for RSpec makes it very hard to limit block length:
16
16
  Metrics/BlockLength:
17
17
  Exclude:
18
18
  - "spec/**/*_spec.rb"
@@ -1,5 +1,10 @@
1
1
  ---
2
2
  language: ruby
3
+
4
+ env:
5
+ global:
6
+ secure: SSSOEixn3ZAtlFmDyczVFAn/a7r+oWt2Ji+CZsRyn3jaXGx27kv0jGVWiTEAjjdEpIjoTSGMoagkP2b0o/+G2ZJgWdlZrLZBI16vmQy/OK386aENKseVsWlH3L6FxDAMDOeK8jRMZEPZWBjfK3MbtG2sfTDqA+kxi1VradFRE/YeLaES8AefbqZvXQgsg9CpLw1rBJTjAxduHVmjS23KY26eNy7wu7Pun4kwHOfmYsT7B/9Dbe9TvB3j01mYHBDbHGK8I+i8qLxU9whB9YhvitgnAY7nvH6aiOTaMKwz81Pr16SdQV+IayG+0dZoY81smSwCjlDdWg9+m/3HtcwU6TAbFCo1TGqQiF6zcvlT3P7hKUEJeCdptXtQuf9PVIjU4AIB1CXAIz2sqWoqRSArAzRmLMjho8RW9Nv7JGz6tN2DCyBOa2G5/+y0knkd8zdXvslCMeBjMn+yf6Ot7NZe4ItTT6YMUqb+Sp3CZzXZtkUqZNYC7BtWn+hLZYj/J48tKYLbFY8wQZ/WswWK9V5SqOuGmIKl/vcLF0DMPcsVotTCvU5Masl+GjBjuzyyGRWViF6qcMXW1QFbuTiQxrF1Gz4jVPL7OA4lflpSOWub+bKzeca71VF8QuFC/pIJoNsnMu39TtCbFhHB7H1NOfqsC63XiWx3JJj/a8d/Z7U5qb8=
7
+
3
8
  cache: bundler
4
9
 
5
10
  rvm:
@@ -7,6 +12,14 @@ rvm:
7
12
  - 2.7
8
13
  - ruby-head
9
14
 
15
+ before_script:
16
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
17
+ - chmod +x ./cc-test-reporter
18
+ - ./cc-test-reporter before-build
19
+
20
+ after_script:
21
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
22
+
10
23
  matrix:
11
24
  allow_failures:
12
25
  - rvm: ruby-head
@@ -1,45 +1,51 @@
1
1
  # Change Log
2
2
 
3
- ## [v0.1.3](https://github.com/jcouball/ruby_git/releases/tag/v0.1.3) (2020-09-24)
3
+ ## [v0.2.0](https://github.com/main-branch/ruby_git/releases/tag/v0.2.0) (2020-10-12)
4
4
 
5
- [Full Changelog](https://github.com/jcouball/ruby_git/compare/v0.1.2...v0.1.3)
5
+ [Full Changelog](https://github.com/main-branch/ruby_git/compare/v0.1.3...v0.2.0)
6
6
 
7
7
  **Merged pull requests:**
8
8
 
9
- - Add Gem badge and correct home page URL [\#10](https://github.com/jcouball/ruby_git/pull/10) ([jcouball](https://github.com/jcouball))
9
+ - Add Worktree class and creation methods init, clone, and open [\#17](https://github.com/main-branch/ruby_git/pull/17) ([jcouball](https://github.com/jcouball))
10
+ - Add Slack badge to README [\#16](https://github.com/main-branch/ruby_git/pull/16) ([jcouball](https://github.com/jcouball))
11
+ - Push code coverage information to CodeClimate [\#14](https://github.com/main-branch/ruby_git/pull/14) ([jcouball](https://github.com/jcouball))
12
+ - Move the ruby\_git repository to the main-branch GitHub organization. [\#13](https://github.com/main-branch/ruby_git/pull/13) ([jcouball](https://github.com/jcouball))
13
+ - Add CODEOWNERS file [\#12](https://github.com/main-branch/ruby_git/pull/12) ([jcouball](https://github.com/jcouball))
14
+ - Release v0.1.3 [\#11](https://github.com/main-branch/ruby_git/pull/11) ([jcouball](https://github.com/jcouball))
10
15
 
11
- ## [v0.1.2](https://github.com/jcouball/ruby_git/releases/tag/v0.1.2) (2020-09-24)
16
+ ## [v0.1.3](https://github.com/main-branch/ruby_git/releases/tag/v0.1.3) (2020-09-24)
12
17
 
13
- [Full Changelog](https://github.com/jcouball/ruby_git/compare/0.1.2...v0.1.2)
18
+ [Full Changelog](https://github.com/main-branch/ruby_git/compare/v0.1.2...v0.1.3)
14
19
 
15
20
  **Merged pull requests:**
16
21
 
17
- - Release v0.1.2 [\#9](https://github.com/jcouball/ruby_git/pull/9) ([jcouball](https://github.com/jcouball))
22
+ - Add Gem badge and correct home page URL [\#10](https://github.com/main-branch/ruby_git/pull/10) ([jcouball](https://github.com/jcouball))
18
23
 
19
- ## [0.1.2](https://github.com/jcouball/ruby_git/releases/tag/0.1.2) (2020-09-24)
24
+ ## [v0.1.2](https://github.com/main-branch/ruby_git/releases/tag/v0.1.2) (2020-09-24)
20
25
 
21
- [Full Changelog](https://github.com/jcouball/ruby_git/compare/v0.1.1...0.1.2)
26
+ [Full Changelog](https://github.com/main-branch/ruby_git/compare/v0.1.1...v0.1.2)
22
27
 
23
28
  **Merged pull requests:**
24
29
 
25
- - Update instructions for creating releases and updating the changelog [\#8](https://github.com/jcouball/ruby_git/pull/8) ([jcouball](https://github.com/jcouball))
26
- - Changes requested in documentation review [\#7](https://github.com/jcouball/ruby_git/pull/7) ([jcouball](https://github.com/jcouball))
27
- - Set and retrieve the path to the git binary used by this library [\#6](https://github.com/jcouball/ruby_git/pull/6) ([jcouball](https://github.com/jcouball))
28
- - Move RSpec config from Rakefile to .rspec [\#5](https://github.com/jcouball/ruby_git/pull/5) ([jcouball](https://github.com/jcouball))
29
- - Release v0.1.1 [\#4](https://github.com/jcouball/ruby_git/pull/4) ([jcouball](https://github.com/jcouball))
30
+ - Release v0.1.2 [\#9](https://github.com/main-branch/ruby_git/pull/9) ([jcouball](https://github.com/jcouball))
31
+ - Update instructions for creating releases and updating the changelog [\#8](https://github.com/main-branch/ruby_git/pull/8) ([jcouball](https://github.com/jcouball))
32
+ - Changes requested in documentation review [\#7](https://github.com/main-branch/ruby_git/pull/7) ([jcouball](https://github.com/jcouball))
33
+ - Set and retrieve the path to the git binary used by this library [\#6](https://github.com/main-branch/ruby_git/pull/6) ([jcouball](https://github.com/jcouball))
34
+ - Move RSpec config from Rakefile to .rspec [\#5](https://github.com/main-branch/ruby_git/pull/5) ([jcouball](https://github.com/jcouball))
35
+ - Release v0.1.1 [\#4](https://github.com/main-branch/ruby_git/pull/4) ([jcouball](https://github.com/jcouball))
30
36
 
31
- ## [v0.1.1](https://github.com/jcouball/ruby_git/releases/tag/v0.1.1) (2020-09-18)
37
+ ## [v0.1.1](https://github.com/main-branch/ruby_git/releases/tag/v0.1.1) (2020-09-18)
32
38
 
33
- [Full Changelog](https://github.com/jcouball/ruby_git/compare/v0.1.0...v0.1.1)
39
+ [Full Changelog](https://github.com/main-branch/ruby_git/compare/v0.1.0...v0.1.1)
34
40
 
35
41
  **Merged pull requests:**
36
42
 
37
- - Add notice saying that this project is a work in progress [\#3](https://github.com/jcouball/ruby_git/pull/3) ([jcouball](https://github.com/jcouball))
38
- - Remove Gemfile.lock and add it to .gitignore [\#2](https://github.com/jcouball/ruby_git/pull/2) ([jcouball](https://github.com/jcouball))
43
+ - Add notice saying that this project is a work in progress [\#3](https://github.com/main-branch/ruby_git/pull/3) ([jcouball](https://github.com/jcouball))
44
+ - Remove Gemfile.lock and add it to .gitignore [\#2](https://github.com/main-branch/ruby_git/pull/2) ([jcouball](https://github.com/jcouball))
39
45
 
40
- ## [v0.1.0](https://github.com/jcouball/ruby_git/releases/tag/v0.1.0) (2020-09-18)
46
+ ## [v0.1.0](https://github.com/main-branch/ruby_git/releases/tag/v0.1.0) (2020-09-18)
41
47
 
42
- [Full Changelog](https://github.com/jcouball/ruby_git/compare/04b4b2bc59b0b09ad45a69572450cb393dbe79a1...v0.1.0)
48
+ [Full Changelog](https://github.com/main-branch/ruby_git/compare/04b4b2bc59b0b09ad45a69572450cb393dbe79a1...v0.1.0)
43
49
 
44
50
 
45
51
 
@@ -0,0 +1,3 @@
1
+ # Defines who must review pull requests.
2
+
3
+ * @jcouball
@@ -20,7 +20,7 @@ You can contribute in two ways:
20
20
  ruby_git utilizes [GitHub Issues](https://help.github.com/en/github/managing-your-work-on-github/about-issues)
21
21
  for issue tracking and feature requests.
22
22
 
23
- Report an issue or feature request by [creating a ruby_git Github issue](https://github.com/jcouball/ruby_git/issues/new).
23
+ Report an issue or feature request by [creating a ruby_git Github issue](https://github.com/main-branch/ruby_git/issues/new).
24
24
  Fill in the template to describe the issue or feature request the best you can.
25
25
 
26
26
  ## How to submit a code or documentation change
@@ -84,7 +84,7 @@ All pull requests must meet these requirements:
84
84
  * The documentation suite must maintain 100% documentation to pass
85
85
 
86
86
  ### Continuous Integration
87
- * All tests must pass in the project's [Travis CI](https://travis-ci.org/jcouball/ruby_git)
87
+ * All tests must pass in the project's [Travis CI](https://travis-ci.org/main-branch/ruby_git)
88
88
  build before the pull request will be merged.
89
89
  * You can simulate what happens in the Travis CI build by running `bundle exec rake` in
90
90
  the projects root directory.
data/README.md CHANGED
@@ -3,8 +3,10 @@
3
3
  **THIS PROJECT IS A WORK IN PROGRESS AND IS NOT USEFUL IN ITS CURRENT STATE**
4
4
 
5
5
  [![Gem Version](https://badge.fury.io/rb/ruby_git.svg)](https://badge.fury.io/rb/ruby_git)
6
- [![Build Status](https://travis-ci.org/jcouball/ruby_git.svg?branch=main)](https://travis-ci.org/jcouball/ruby_git)
7
- [![Maintainability](https://api.codeclimate.com/v1/badges/2d8d52a55d655b6a3def/maintainability)](https://codeclimate.com/github/jcouball/ruby_git/maintainability)
6
+ [![Build Status](https://travis-ci.org/main-branch/ruby_git.svg?branch=main)](https://travis-ci.org/main-branch/ruby_git)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/5403e4613b7518f70da7/maintainability)](https://codeclimate.com/github/main-branch/ruby_git/maintainability)
8
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/5403e4613b7518f70da7/test_coverage)](https://codeclimate.com/github/main-branch/ruby_git/test_coverage)
9
+ [![Slack](https://img.shields.io/badge/slack-main--branch/ruby__git-yellow.svg?logo=slack)](https://main-branch.slack.com/archives/C01CHR7TMM2)
8
10
 
9
11
  RubyGit is an object-oriented wrapper for the `git` command line tool for working with Worktrees
10
12
  and Repositories. It tries to make more sense out of the Git command line. See the object model
@@ -65,7 +67,7 @@ To tell what version of Git is being used:
65
67
  puts RubyGit.git_version
66
68
  ```
67
69
 
68
- The full API is documented in [the RubyGit YARD documentation](https://github.com/pages/jcouball/ruby_git).
70
+ The full API is documented in [the RubyGit YARD documentation](https://github.com/pages/main-branch/ruby_git).
69
71
 
70
72
  ## Development
71
73
 
@@ -77,4 +79,4 @@ automatically requires ruby_git.
77
79
 
78
80
  ## Contributing
79
81
 
80
- Bug reports and pull requests are welcome on GitHub at https://github.com/jcouball/ruby_git.
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/main-branch/ruby_git.
@@ -33,7 +33,7 @@ version number and (2) update the CHANGELOG.md, and (3) tag the release.
33
33
 
34
34
  ## Create a GitHub release
35
35
 
36
- On [the ruby_git releases page](https://github.com/jcouball/ruby_git/releases),
36
+ On [the ruby_git releases page](https://github.com/main-branch/ruby_git/releases),
37
37
  select `Draft a new release`
38
38
 
39
39
  * Select the tag corresponding to the version being released `v1.1.0.pre1`
@@ -45,7 +45,7 @@ select `Draft a new release`
45
45
 
46
46
  ## Build and release the gem
47
47
 
48
- Clone [jcouball/ruby_git](https://github.com/jcouball/ruby_git) directly (not a
48
+ Clone [main-branch/ruby_git](https://github.com/main-branch/ruby_git) directly (not a
49
49
  fork) and ensure your local working copy is on the main branch
50
50
 
51
51
  * Verify that you are not on a fork with the command `git remote -v`
data/Rakefile CHANGED
@@ -70,9 +70,9 @@ require 'github_changelog_generator/task'
70
70
 
71
71
  GitHubChangelogGenerator::RakeTask.new :changelog do |config|
72
72
  config.header = '# Change Log'
73
- config.user = 'jcouball'
73
+ config.user = 'main-branch'
74
74
  config.project = 'ruby_git'
75
75
  config.future_release = "v#{RubyGit::VERSION}"
76
- config.release_url = 'https://github.com/jcouball/ruby_git/releases/tag/%s'
76
+ config.release_url = 'https://github.com/main-branch/ruby_git/releases/tag/%s'
77
77
  config.author = true
78
78
  end
@@ -1,8 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ruby_git/version'
3
+ require 'ruby_git/error'
4
4
  require 'ruby_git/file_helpers'
5
5
  require 'ruby_git/git_binary'
6
+ require 'ruby_git/version'
7
+ require 'ruby_git/worktree'
6
8
 
7
9
  # RubyGit is an object-oriented wrapper for the `git` command line tool for
8
10
  # working with Worktrees and Repositories. It tries to make more sense out
@@ -24,4 +26,79 @@ module RubyGit
24
26
  def self.git
25
27
  (@git ||= RubyGit::GitBinary.new)
26
28
  end
29
+
30
+ # Create an empty Git repository under the root worktree `path`
31
+ #
32
+ # If the repository already exists, it will not be overwritten.
33
+ #
34
+ # @see https://git-scm.com/docs/git-init git-init
35
+ #
36
+ # @example
37
+ # worktree = Worktree.init(worktree_path)
38
+ #
39
+ # @param [String] worktree_path the root path of a worktree
40
+ #
41
+ # @raise [RubyGit::Error] if worktree_path is not a directory
42
+ #
43
+ # @return [RubyGit::Worktree] the worktree whose root is at `path`
44
+ #
45
+ def self.init(worktree_path)
46
+ RubyGit::Worktree.init(worktree_path)
47
+ end
48
+
49
+ # Open an existing Git worktree that contains worktree_path
50
+ #
51
+ # @see https://git-scm.com/docs/git-open git-open
52
+ #
53
+ # @example
54
+ # worktree = Worktree.open(worktree_path)
55
+ #
56
+ # @param [String] worktree_path the root path of a worktree
57
+ #
58
+ # @raise [RubyGit::Error] if `worktree_path` does not exist, is not a directory, or is not within a Git worktree.
59
+ #
60
+ # @return [RubyGit::Worktree] the worktree that contains `worktree_path`
61
+ #
62
+ def self.open(worktree_path)
63
+ RubyGit::Worktree.open(worktree_path)
64
+ end
65
+
66
+ # Copy the remote repository and checkout the default branch
67
+ #
68
+ # Clones the repository referred to by `repository_url` into a newly created
69
+ # directory, creates remote-tracking branches for each branch in the cloned repository,
70
+ # and checks out the default branch in the worktree whose root directory is `to_path`.
71
+ #
72
+ # @see https://git-scm.com/docs/git-clone git-clone
73
+ #
74
+ # @example Using default for Worktree path
75
+ # FileUtils.pwd
76
+ # => "/Users/jsmith"
77
+ # worktree = Worktree.clone('https://github.com/main-branch/ruby_git.git')
78
+ # worktree.path
79
+ # => "/Users/jsmith/ruby_git"
80
+ #
81
+ # @example Using a specified worktree_path
82
+ # FileUtils.pwd
83
+ # => "/Users/jsmith"
84
+ # worktree_path = '/tmp/project'
85
+ # worktree = Worktree.clone('https://github.com/main-branch/ruby_git.git', to_path: worktree_path)
86
+ # worktree.path
87
+ # => "/tmp/project"
88
+ #
89
+ # @param [String] repository_url a reference to a Git repository
90
+ #
91
+ # @param [String] to_path where to put the checked out worktree once the repository is cloned
92
+ #
93
+ # `to_path` will be created if it does not exist. An error is raised if `to_path` exists and
94
+ # not an empty directory.
95
+ #
96
+ # @raise [RubyGit::Error] if (1) `repository_url` is not valid or does not point to a valid repository OR
97
+ # (2) `to_path` is not an empty directory.
98
+ #
99
+ # @return [RubyGit::Worktree] the worktree checked out from the cloned repository
100
+ #
101
+ def self.clone(repository_url, to_path: '')
102
+ RubyGit::Worktree.clone(repository_url, to_path: to_path)
103
+ end
27
104
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyGit
4
+ # Errors specific to RubyGit raise RubyGit::Error
5
+ #
6
+ class Error < StandardError
7
+ end
8
+ end
@@ -11,8 +11,8 @@ module RubyGit
11
11
  # @example
12
12
  # GitBinary.new
13
13
  #
14
- def initialize
15
- @path = nil
14
+ def initialize(path = nil)
15
+ @path = Pathname.new(path) unless path.nil?
16
16
  end
17
17
 
18
18
  # Sets the path to the git binary
@@ -86,5 +86,21 @@ module RubyGit
86
86
  version = output[/\d+\.\d+(\.\d+)+/]
87
87
  version.split('.').collect(&:to_i)
88
88
  end
89
+
90
+ # Return the path as a string
91
+ #
92
+ # @example
93
+ # git = RubyGit::GitBinary.new('/usr/bin/git')
94
+ # git.to_s
95
+ # => '/usr/bin/git'
96
+ #
97
+ # @return [String] the path to the binary
98
+ #
99
+ # @raise [RuntimeError] if path was not set via `path=` and either PATH is not set
100
+ # or git was not found on the path.
101
+ #
102
+ def to_s
103
+ path.to_s
104
+ end
89
105
  end
90
106
  end
@@ -3,5 +3,5 @@
3
3
  module RubyGit
4
4
  # The ruby_git gem version
5
5
  #
6
- VERSION = '0.1.3'
6
+ VERSION = '0.2.0'
7
7
  end
@@ -0,0 +1,135 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'open3'
4
+
5
+ module RubyGit
6
+ # The Worktree is a directory tree consisting of the checked out files that
7
+ # you are currently working on.
8
+ #
9
+ # Create a new Worktree using {.init}, {.clone}, or {.open}.
10
+ #
11
+ class Worktree
12
+ # The root path of the worktree
13
+ #
14
+ # @example
15
+ # worktree_path = '/Users/James/myproject'
16
+ # worktree = Worktree.open(worktree_path)
17
+ # worktree.path
18
+ # => '/Users/James/myproject'
19
+ #
20
+ # @return [Pathname] the root path of the worktree
21
+ #
22
+ attr_reader :path
23
+
24
+ # Create an empty Git repository under the root worktree `path`
25
+ #
26
+ # If the repository already exists, it will not be overwritten.
27
+ #
28
+ # @see https://git-scm.com/docs/git-init git-init
29
+ #
30
+ # @example
31
+ # worktree = Worktree.init(worktree_path)
32
+ #
33
+ # @param [String] worktree_path the root path of a worktree
34
+ #
35
+ # @raise [RubyGit::Error] if worktree_path is not a directory
36
+ #
37
+ # @return [RubyGit::Worktree] the worktree whose root is at `path`
38
+ #
39
+ def self.init(worktree_path)
40
+ raise RubyGit::Error, "Path '#{worktree_path}' not valid." unless File.directory?(worktree_path)
41
+
42
+ command = [RubyGit.git.path.to_s, 'init']
43
+ _out, err, status = Open3.capture3(*command, chdir: worktree_path)
44
+ raise RubyGit::Error, err unless status.success?
45
+
46
+ Worktree.new(worktree_path)
47
+ end
48
+
49
+ # Open an existing Git worktree that contains worktree_path
50
+ #
51
+ # @see https://git-scm.com/docs/git-open git-open
52
+ #
53
+ # @example
54
+ # worktree = Worktree.open(worktree_path)
55
+ #
56
+ # @param [String] worktree_path the root path of a worktree
57
+ #
58
+ # @raise [RubyGit::Error] if `worktree_path` does not exist, is not a directory, or is not within a Git worktree.
59
+ #
60
+ # @return [RubyGit::Worktree] the worktree that contains `worktree_path`
61
+ #
62
+ def self.open(worktree_path)
63
+ new(worktree_path)
64
+ end
65
+
66
+ # Copy the remote repository and checkout the default branch
67
+ #
68
+ # Clones the repository referred to by `repository_url` into a newly created
69
+ # directory, creates remote-tracking branches for each branch in the cloned repository,
70
+ # and checks out the default branch in the worktree whose root directory is `to_path`.
71
+ #
72
+ # @see https://git-scm.com/docs/git-clone git-clone
73
+ #
74
+ # @example Using default for Worktree path
75
+ # FileUtils.pwd
76
+ # => "/Users/jsmith"
77
+ # worktree = Worktree.clone('https://github.com/main-branch/ruby_git.git')
78
+ # worktree.path
79
+ # => "/Users/jsmith/ruby_git"
80
+ #
81
+ # @example Using a specified worktree_path
82
+ # FileUtils.pwd
83
+ # => "/Users/jsmith"
84
+ # worktree_path = '/tmp/project'
85
+ # worktree = Worktree.clone('https://github.com/main-branch/ruby_git.git', to_path: worktree_path)
86
+ # worktree.path
87
+ # => "/tmp/project"
88
+ #
89
+ # @param [String] repository_url a reference to a Git repository
90
+ #
91
+ # @param [String] to_path where to put the checked out worktree once the repository is cloned
92
+ #
93
+ # `to_path` will be created if it does not exist. An error is raised if `to_path` exists and
94
+ # not an empty directory.
95
+ #
96
+ # @raise [RubyGit::Error] if (1) `repository_url` is not valid or does not point to a valid repository OR
97
+ # (2) `to_path` is not an empty directory.
98
+ #
99
+ # @return [RubyGit::Worktree] the worktree checked out from the cloned repository
100
+ #
101
+ def self.clone(repository_url, to_path: '')
102
+ command = [RubyGit.git.path.to_s, 'clone', '--', repository_url, to_path]
103
+ _out, err, status = Open3.capture3(*command)
104
+ raise RubyGit::Error, err unless status.success?
105
+
106
+ new(to_path)
107
+ end
108
+
109
+ private
110
+
111
+ # Create a Worktree object
112
+ # @api private
113
+ def initialize(worktree_path)
114
+ raise RubyGit::Error, "Path '#{worktree_path}' not valid." unless File.directory?(worktree_path)
115
+
116
+ @path = root_path(worktree_path)
117
+ end
118
+
119
+ # Find the root path of a worktree containing `path`
120
+ #
121
+ # @raise [RubyGit::Error] if the path is not in a worktree
122
+ #
123
+ # @return [String] the root path of the worktree containing `path`
124
+ #
125
+ # @api private
126
+ #
127
+ def root_path(worktree_path)
128
+ command = [RubyGit.git.path.to_s, 'rev-parse', '--show-toplevel']
129
+ out, err, status = Open3.capture3(*command, chdir: worktree_path)
130
+ raise RubyGit::Error, err unless status.success?
131
+
132
+ out.chomp
133
+ end
134
+ end
135
+ end
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
16
16
  An object-oriented interface to working with Git Worktrees and Repositories that
17
17
  tries to make sense out of the Git command line.
18
18
  DESCRIPTION
19
- spec.homepage = 'https://github.com/jcouball/ruby_git/'
19
+ spec.homepage = 'https://github.com/main-branch/ruby_git/'
20
20
  spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
21
21
  spec.requirements = [
22
22
  'Git 2.18.0 or later',
@@ -28,8 +28,8 @@ Gem::Specification.new do |spec|
28
28
  spec.metadata['allowed_push_host'] = 'https://rubygems.org'
29
29
 
30
30
  spec.metadata['homepage_uri'] = spec.homepage
31
- spec.metadata['source_code_uri'] = 'https://github.com/jcouball/ruby_git/'
32
- spec.metadata['changelog_uri'] = 'https://github.com/jcouball/ruby_git/blob/main/CHANGELOG.md'
31
+ spec.metadata['source_code_uri'] = 'https://github.com/main-branch/ruby_git/'
32
+ spec.metadata['changelog_uri'] = 'https://github.com/main-branch/ruby_git/blob/main/CHANGELOG.md'
33
33
 
34
34
  # Specify which files should be added to the gem when it is released.
35
35
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_git
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Couball
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-09-24 00:00:00.000000000 Z
11
+ date: 2020-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bump
@@ -167,6 +167,7 @@ files:
167
167
  - ".travis.yml"
168
168
  - ".yardopts"
169
169
  - CHANGELOG.md
170
+ - CODEOWNERS
170
171
  - CONTRIBUTING.md
171
172
  - Gemfile
172
173
  - ISSUE_TEMPLATE.md
@@ -179,19 +180,21 @@ files:
179
180
  - bin/console
180
181
  - bin/setup
181
182
  - lib/ruby_git.rb
183
+ - lib/ruby_git/error.rb
182
184
  - lib/ruby_git/file_helpers.rb
183
185
  - lib/ruby_git/git_binary.rb
184
186
  - lib/ruby_git/version.rb
187
+ - lib/ruby_git/worktree.rb
185
188
  - pre-commit
186
189
  - ruby_git.gemspec
187
- homepage: https://github.com/jcouball/ruby_git/
190
+ homepage: https://github.com/main-branch/ruby_git/
188
191
  licenses:
189
192
  - MIT
190
193
  metadata:
191
194
  allowed_push_host: https://rubygems.org
192
- homepage_uri: https://github.com/jcouball/ruby_git/
193
- source_code_uri: https://github.com/jcouball/ruby_git/
194
- changelog_uri: https://github.com/jcouball/ruby_git/blob/main/CHANGELOG.md
195
+ homepage_uri: https://github.com/main-branch/ruby_git/
196
+ source_code_uri: https://github.com/main-branch/ruby_git/
197
+ changelog_uri: https://github.com/main-branch/ruby_git/blob/main/CHANGELOG.md
195
198
  post_install_message:
196
199
  rdoc_options: []
197
200
  require_paths:
@@ -211,7 +214,7 @@ requirements:
211
214
  - Ruby 2.6 or later
212
215
  - Only MRI Ruby and JRuby are officially supported.
213
216
  - Mac, Linux, Unix, and Windows platforms are supported
214
- rubygems_version: 3.1.2
217
+ rubygems_version: 3.1.4
215
218
  signing_key:
216
219
  specification_version: 4
217
220
  summary: A Ruby library to work with Git Worktrees and Respositories