Module: TinyCI::GitUtils
Overview
Methods for dealing with git repos.
Instance Method Summary collapse
-
#git_cmd(*args) ⇒ Object
Execute a git command, passing the -C parameter if the current object has the working_directory instance var set.
-
#git_directory_path ⇒ Object
Returns the absolute path to the .git directory.
-
#inside_bare_repo? ⇒ Boolean
Are we under a bare repo?.
-
#inside_git_directory? ⇒ Boolean
Are we currently under a git repo?.
-
#inside_repository? ⇒ Boolean
Are we currently under a repo in any sense?.
-
#inside_work_tree? ⇒ Boolean
Are we currently under a git work tree?.
-
#repo_root ⇒ String
Returns the absolute path to the root of the current git directory.
Instance Method Details
#git_cmd(*args) ⇒ Object
Execute a git command, passing the -C parameter if the current object has the working_directory instance var set
50 51 52 53 54 55 56 |
# File 'lib/tinyci/git_utils.rb', line 50 def git_cmd(*args) cmd = ['git'] cmd += ['-C', @working_dir] if defined?(@working_dir) && !@working_dir.nil? cmd += args cmd end |
#git_directory_path ⇒ Object
Returns the absolute path to the .git directory
44 45 46 |
# File 'lib/tinyci/git_utils.rb', line 44 def git_directory_path File.(execute(git_cmd('rev-parse', '--git-dir')), defined?(@working_dir) ? @working_dir : nil) end |
#inside_bare_repo? ⇒ Boolean
Are we under a bare repo?
29 30 31 |
# File 'lib/tinyci/git_utils.rb', line 29 def execute(git_cmd('rev-parse', '--is-bare-repository')) == 'true' end |
#inside_git_directory? ⇒ Boolean
Are we currently under a git repo?
24 25 26 |
# File 'lib/tinyci/git_utils.rb', line 24 def inside_git_directory? execute(git_cmd('rev-parse', '--is-inside-git-dir')) == 'true' end |
#inside_repository? ⇒ Boolean
Are we currently under a repo in any sense?
39 40 41 |
# File 'lib/tinyci/git_utils.rb', line 39 def inside_repository? execute(git_cmd('rev-parse', '--is-inside-work-tree', '--is-inside-git-dir')).split.any? {|s| s == 'true'} end |
#inside_work_tree? ⇒ Boolean
Are we currently under a git work tree?
34 35 36 |
# File 'lib/tinyci/git_utils.rb', line 34 def inside_work_tree? execute(git_cmd('rev-parse', '--is-inside-work-tree')) == 'true' end |
#repo_root ⇒ String
Returns the absolute path to the root of the current git directory
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/tinyci/git_utils.rb', line 11 def repo_root return git_directory_path if if inside_git_directory? File.('..', git_directory_path) elsif inside_work_tree? execute(git_cmd('rev-parse', '--show-toplevel')) else raise 'not in git directory or work tree!?' end end |