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.



12
13
14
15
16
# File 'lib/autoversion/gitter.rb', line 12

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

Instance Method Details

#commit!(versionType, currentVersion) ⇒ Object

Raises:



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

def commit! versionType, currentVersion
  return false unless @config[:actions].include?(:commit)
  raise NotOnStableBranch if versionType == :major && !on_stable_branch?

  write_commit currentVersion
  write_tag currentVersion if @config[:actions].include?(:tag)
end

#dir_is_clean?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/autoversion/gitter.rb', line 24

def dir_is_clean?
  # sum = @repo.status.untracked.length + @repo.status.added.length + @repo.status.changed.length + @repo.status.deleted.length
  # if sum > 0
  #   puts "untracked: #{@repo.status.untracked}"
  #   puts "added: #{@repo.status.added}"
  #   puts "changed: #{@repo.status.changed}"
  #   puts "deleted: #{@repo.status.deleted}"
  # end

  # sum == 0

  # Disabled for now. ruby-git doesn't seem to read the .gitignore files, so the untracked count is completely useless. 
  true
end

#ensure_cleanliness!Object



18
19
20
21
22
# File 'lib/autoversion/gitter.rb', line 18

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

#on_stable_branch?Boolean

Returns:

  • (Boolean)


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

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