Module: Bake::Modernize::Git

Defined in:
lib/bake/modernize/git.rb

Overview

Utilities for inspecting git repositories.

Class Method Summary collapse

Class Method Details

.current_branch(root = Dir.pwd, default: nil) ⇒ Object

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



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/bake/modernize/git.rb', line 13

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