Class: Autoversion::Gitter

Inherits:
Object
  • Object
show all
Defined in:
lib/autoversion/gitter.rb

Defined Under Namespace

Classes: DirtyStaging, NotOnStableBranch

Instance Method Summary collapse

Constructor Details

#initialize(path, config) ⇒ Gitter

Returns a new instance of Gitter.



15
16
17
18
19
# File 'lib/autoversion/gitter.rb', line 15

def initialize path, config
  @path = path
  @config = config
  @repo = Git.open(path)
end

Instance Method Details

#commit!(versionType, currentVersion) ⇒ Object



44
45
46
47
48
49
# File 'lib/autoversion/gitter.rb', line 44

def commit! versionType, currentVersion
  return false unless @config[:actions].include?(:commit) 
   
  write_commit currentVersion
  write_tag currentVersion if @config[:actions].include?(:tag)
end

#dir_is_clean?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
36
37
38
# File 'lib/autoversion/gitter.rb', line 31

def dir_is_clean?
  sum = gitstatus_untracked_workaround.length +
        @repo.status.added.length +
        @repo.status.changed.length +
        @repo.status.deleted.length

  sum == 0
end

#ensure_cleanliness!Object



21
22
23
24
25
# File 'lib/autoversion/gitter.rb', line 21

def ensure_cleanliness!
  if @config[:actions].include?(:commit)
    raise DirtyStaging unless dir_is_clean?
  end
end

#ensure_valid_branch!(versionType) ⇒ Object

Raises:



27
28
29
# File 'lib/autoversion/gitter.rb', line 27

def ensure_valid_branch! versionType
  raise NotOnStableBranch.new(@config[:stable_branch]) if versionType == :major && !on_stable_branch?
end

#on_stable_branch?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/autoversion/gitter.rb', line 40

def on_stable_branch?
  @repo.current_branch == @config[:stable_branch].to_s
end