Module: Repos
- Defined in:
- lib/repos.rb,
lib/repos/cli.rb,
lib/repos/version.rb
Overview
The main module of repos, which includes its core functionality and more modules for supporting functionality.
Defined Under Namespace
Classes: CLI
Constant Summary collapse
- VERSION =
The version number of the gem.
'0.1.0'
Class Method Summary collapse
-
.clean?(repository) ⇒ Boolean
Returns true when the given repository has neigher uncommitted changes nor untracked files.
-
.list(directory, filter = 'all', recursive = false) ⇒ Object
Lists all Git repository in the current directory.
Class Method Details
.clean?(repository) ⇒ Boolean
Returns true when the given repository has neigher uncommitted changes nor untracked files. Expects the repository to have at least one commit.
Attributes
-
repository- A String of the path to the repository to check. The path can be absolute or relative.
39 40 41 42 43 44 45 |
# File 'lib/repos.rb', line 39 def self.clean?(repository) Dir.chdir(repository) do empty_diff = system('git diff-index --quiet HEAD') untracked = `git ls-files --other --directory --exclude-standard` != '' empty_diff && !untracked end end |
.list(directory, filter = 'all', recursive = false) ⇒ Object
Lists all Git repository in the current directory. When recursive is true, it also lists Git repositories found in subdirectories.
Attributes
-
directory- A String of the path to search for repositories within. This method will not check to see if the directory itself is a git repository. The path can be absolute or relative. -
filter- ‘clean’ to find clean repositories only, ‘dirty’ to find dirty repositories only, and anything else to find all repositories (dirty or clean). -
recursive- True if Git repositories should be searched for within subdirectories.
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/repos.rb', line 19 def self.list(directory, filter = 'all', recursive = false) pattern = recursive ? '**/.git' : '*/.git' repositories = Dir.glob("#{directory}/#{pattern}").sort.map do |git_directory| Pathname.new(git_directory).dirname.to_s end is_clean = proc { |repository| Repos.clean?(repository) } case filter when 'clean' then repositories.select(&is_clean) when 'dirty' then repositories.reject(&is_clean) else repositories end end |