Bake ModernizeSourceBakeModernizeGit

module Git

Utilities for inspecting git repositories.

Definitions

def self.current_branch(root = Dir.pwd, default: nil)

The current branch name for the repository at the given root.

Implementation

def self.current_branch(root = Dir.pwd, default: nil)
	begin
		repository = Rugged::Repository.discover(root)
		head = repository.head
		
		if head.branch?
			return head.name.delete_prefix("refs/heads/")
		end
	rescue Rugged::ReferenceError, Rugged::RepositoryError
	end
	
	return default
end