class Status
A command to show git status of packages.
Definitions
def terminal(output = $stdout)
Create a terminal with custom styles for colorizing git status information.
Signature
-
parameter
outputIO The output stream.
-
returns
Console::Terminal The configured terminal.
Implementation
def terminal(output = $stdout)
Console::Terminal.for(output).tap do |terminal|
terminal[:worktree_new] = terminal.style(:green)
terminal[:worktree_modified] = terminal.style(:yellow)
terminal[:worktree_deleted] = terminal.style(:red)
end
end
def repository_for(package)
Open the git repository for a package, or return nil if the package doesn't have a repository yet.
Signature
-
parameter
packagePackage The package.
-
returns
Rugged::Repository | Nil The repository or nil.
Implementation
def repository_for(package)
Rugged::Repository.new(package.path.to_s)
rescue Rugged::RepositoryError
# In some cases, a repository might not exist yet, so just skip the package.
nil
end
def process(selection)
Process and display the selection.
Signature
-
parameter
selectionSelect The selection to process.
Implementation
def process(selection)
context = selection.context
terminal = self.terminal
selection.resolved.each do |package|
if repository = repository_for(package)
changes = {}
repository.status do |file, status|
unless status == [:ignored]
changes[file] = status
end
end
next if changes.empty?
terminal.puts "Package #{package.name} (from #{package.path}):"
changes.each do |file, statuses|
terminal.puts "\t#{file} (#{statuses})", style: statuses.last
end
end
end
end