Module: Guard::Notifier::GitAutoCommit

Extended by:
GitAutoCommit
Included in:
GitAutoCommit
Defined in:
lib/version.rb,
lib/guard/notifiers/git_auto_commit.rb

Constant Summary collapse

VERSION =
"0.1.2"

Instance Method Summary collapse

Instance Method Details

#available?(silent = false) ⇒ Boolean

Test if the current directory is managed using git.

Parameters:

  • silent (Boolean) (defaults to: false)

    true if no error messages should be shown

Returns:

  • (Boolean)

    the availability status



14
15
16
# File 'lib/guard/notifiers/git_auto_commit.rb', line 14

def available?(silent = false)
  system("git status > /dev/null 2> /dev/null")
end

#notify(type, title, message, image, options = { }) ⇒ Object

Show a system notification.

Parameters:

  • type (String)

    the notification type. Either ‘success’, ‘pending’, ‘failed’ or ‘notify’

  • title (String)

    the notification title

  • message (String)

    the notification message body

  • image (String)

    the path to the notification image

  • options (Hash) (defaults to: { })

    additional notification library options

Options Hash (options):

  • sticky (Boolean)

    make the notification sticky

  • priority (String, Integer)

    specify an int or named key (default is 0)



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/guard/notifiers/git_auto_commit.rb', line 28

def notify(type, title, message, image, options = { })
  commit_message = [type, title, message].join('  ').gsub(/\r|\n/, '')
  commit_message << "\n\n"
  system("git add -u")
  commit_message << `git diff --cached`
  File.popen("git commit -F -", "r+") do |fd|
    fd.write commit_message
    fd.close
  end

  # notify untracked files
  untracked_files = `git ls-files --exclude-standard --others`.split("\n")
  unless untracked_files.select { |path|
      ! File.basename(path).match(/^\.|~$/) }.empty?
    warn "\e[35mYou have untracked file\e[0m"
  end
end