rugged icon indicating copy to clipboard operation
rugged copied to clipboard

Repository#status is hard to use.

Open ioquatix opened this issue 8 years ago • 3 comments

Here is an example:

changes = {}
repository.status do |file, status|
	unless status == [:ignored]
		changes[file] = status
	end
end

next if changes.empty?

logger.info "Package #{package.name} (from #{package.path}):".bright

changes.each do |file, status|
	if status == [:worktree_new]
		logger.info "\t#{file}".color(:blue)
	elsif status == [:worktree_modified]
		logger.info "\t#{file}".color(:orange)
	elsif status == [:worktree_deleted]
		logger.info "\t#{file}".color(:red)
	else
		logger.info "\t#{file} #{status.inspect}"
	end
end

I firstly have to assemble the list of changes into a hash, then check if it's empty, before finally printing out details.

It would be nice if you could write changes = repository.status or even better, if repository.status could return a chainable enumerable to_enum.

ioquatix avatar Jul 06 '17 00:07 ioquatix

So, I could write, for example:

changes = repository.status.select{|file, status| status != [:ignored]}

ioquatix avatar Jul 06 '17 00:07 ioquatix

Maybe even better would be if the API could filter out this data before even coming to Ruby-land:

changes = repository.status(ignored: false)

ioquatix avatar Jul 06 '17 00:07 ioquatix

Here is another example of what I think would be nice to do:

# Check dirty status of local repository:
if context.repository.status(ignored: false).any?
    abort "You have unstaged changes/unadded files. Please stash/commit them before running the generator.".color(:red)
end

ioquatix avatar Jul 06 '17 03:07 ioquatix