Class: Gitw::Repository
- Inherits:
-
Object
- Object
- Gitw::Repository
- Extended by:
- Forwardable
- Defined in:
- lib/gitw/repository.rb
Overview
git repository service
Instance Attribute Summary collapse
-
#base_dir ⇒ Object
readonly
Returns the value of attribute base_dir.
Class Method Summary collapse
-
.at(directory = '.', **options) ⇒ Object
self end.
- .clone(from, to = nil, **options) ⇒ Object
- .init(directory = '.', **options) ⇒ Object
Instance Method Summary collapse
- #absolute_git_dir ⇒ Object
- #bare? ⇒ Boolean
- #clone_from(url, **options) ⇒ Object
- #git(options = git_options) ⇒ Object
- #git_base_options ⇒ Object
- #git_dir ⇒ Object
- #git_options ⇒ Object
- #in_repository? ⇒ Boolean
- #init(**options) ⇒ Object
-
#initialize(base_dir = '.', **options) ⇒ Repository
constructor
A new instance of Repository.
- #inside_git_dir? ⇒ Boolean
- #inside_work_tree? ⇒ Boolean
- #root_dir ⇒ Object
- #toplevel ⇒ Object
- #worktree_dir ⇒ Object
Constructor Details
#initialize(base_dir = '.', **options) ⇒ Repository
Returns a new instance of Repository.
14 15 16 17 18 |
# File 'lib/gitw/repository.rb', line 14 def initialize(base_dir = '.', **) @base_dir = File.(base_dir) @git_dir = [:git_dir] || ['git_dir'] @worktree_dir = [:worktree_dir] || ['worktree_dir'] end |
Instance Attribute Details
#base_dir ⇒ Object (readonly)
Returns the value of attribute base_dir.
12 13 14 |
# File 'lib/gitw/repository.rb', line 12 def base_dir @base_dir end |
Class Method Details
.at(directory = '.', **options) ⇒ Object
self end
184 185 186 187 188 189 |
# File 'lib/gitw/repository.rb', line 184 def self.at(directory = '.', **) repository = new(directory, **) return nil unless repository.in_repository? repository end |
.clone(from, to = nil, **options) ⇒ Object
195 196 197 198 199 200 201 |
# File 'lib/gitw/repository.rb', line 195 def self.clone(from, to = nil, **) return unless from from_url = Gitw::Git::URL.new(from) to ||= from_url.basename new(to, **).clone_from(from_url, **) end |
.init(directory = '.', **options) ⇒ Object
191 192 193 |
# File 'lib/gitw/repository.rb', line 191 def self.init(directory = '.', **) new(directory, **).init(**) end |
Instance Method Details
#absolute_git_dir ⇒ Object
53 54 55 56 57 |
# File 'lib/gitw/repository.rb', line 53 def absolute_git_dir git.absolute_git_dir rescue Gitw::GitError nil end |
#bare? ⇒ Boolean
59 60 61 62 63 |
# File 'lib/gitw/repository.rb', line 59 def git. rescue Gitw::GitError false end |
#clone_from(url, **options) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/gitw/repository.rb', line 82 def clone_from(url, **) FileUtils.mkdir_p base_dir git().clone(url.to_s, base_dir, **) self rescue Errno::EACCES, Gitw::GitError nil end |
#git(options = git_options) ⇒ Object
91 92 93 94 95 |
# File 'lib/gitw/repository.rb', line 91 def git( = ) Dir.chdir(base_dir) do Gitw::GitExe.new(options: ) end end |
#git_base_options ⇒ Object
105 106 107 108 109 110 |
# File 'lib/gitw/repository.rb', line 105 def { git_dir: git_dir, work_tree: worktree_dir }.compact end |
#git_dir ⇒ Object
20 21 22 |
# File 'lib/gitw/repository.rb', line 20 def git_dir return @git_dir if @git_dir end |
#git_options ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/gitw/repository.rb', line 97 def .merge( { dir: base_dir } ).compact end |
#in_repository? ⇒ Boolean
28 29 30 31 32 33 |
# File 'lib/gitw/repository.rb', line 28 def in_repository? return false unless File.directory?(base_dir) return true if inside_work_tree? || inside_git_dir? false end |
#init(**options) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/gitw/repository.rb', line 73 def init(**) FileUtils.mkdir_p base_dir git.init(base_dir, **) self rescue Errno::EACCES, Gitw::GitError nil end |
#inside_git_dir? ⇒ Boolean
41 42 43 44 45 |
# File 'lib/gitw/repository.rb', line 41 def inside_git_dir? git.is_inside_git_dir rescue Gitw::GitError false end |
#inside_work_tree? ⇒ Boolean
35 36 37 38 39 |
# File 'lib/gitw/repository.rb', line 35 def inside_work_tree? git.is_inside_work_tree rescue Gitw::GitError false end |
#root_dir ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/gitw/repository.rb', line 65 def root_dir return absolute_git_dir if git.toplevel rescue Gitw::GitError nil end |
#toplevel ⇒ Object
47 48 49 50 51 |
# File 'lib/gitw/repository.rb', line 47 def toplevel git.toplevel rescue Gitw::GitError nil end |
#worktree_dir ⇒ Object
24 25 26 |
# File 'lib/gitw/repository.rb', line 24 def worktree_dir return @worktree_dir if @worktree_dir end |