Class: CreateGithubRelease::Assertions::InRepoRootDirectory

Inherits:
CreateGithubRelease::AssertionBase show all
Defined in:
lib/create_github_release/assertions/in_repo_root_directory.rb

Overview

Assert that the current directory is the root of the repository

Checks both the local repository and the remote repository.

Instance Attribute Summary

Attributes inherited from CreateGithubRelease::AssertionBase

#project

Instance Method Summary collapse

Methods inherited from CreateGithubRelease::AssertionBase

#backtick_debug?, #error, #initialize, #print, #puts

Methods included from BacktickDebug

#`

Constructor Details

This class inherits a constructor from CreateGithubRelease::AssertionBase

Instance Method Details

#assert

This method returns an undefined value.

Make sure that the current directory is the root of the repository

Examples:

require 'create_github_release'

options = CreateGithubRelease::CommandLine::Options.new { |o| o.release_type = 'major' }
project = CreateGithubRelease::Project.new(options)
assertion = CreateGithubRelease::Assertions::InRepoRootDirectory.new(project)
begin
  assertion.assert
  puts 'Assertion passed'
rescue SystemExit
  puts 'Assertion failed'
end

Raises:

  • (SystemExit)

    if the assertion fails



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/create_github_release/assertions/in_repo_root_directory.rb', line 35

def assert
  print "Checking that you are in the repo's root directory..."
  toplevel_directory = `git rev-parse --show-toplevel`.chomp
  error "git rev-parse failed: #{$CHILD_STATUS.exitstatus}" unless $CHILD_STATUS.success?

  if toplevel_directory == FileUtils.pwd
    puts 'OK'
  else
    error "You are not in the repo's root directory"
  end
end