Class: Babushka::GitFS

Inherits:
Object show all
Defined in:
lib/babushka/git_fs.rb

Constant Summary collapse

GITIGNORE_FILE =
(Babushka::Path.path / 'conf/git_fs_gitignore')

Class Method Summary collapse

Class Method Details

.commit(message) ⇒ Object


14
15
16
17
# File 'lib/babushka/git_fs.rb', line 14

def self.commit message
  repo.repo_shell_as_owner('git add -A .')
  repo.commit!(message)
end

.initObject


19
20
21
22
23
24
25
# File 'lib/babushka/git_fs.rb', line 19

def self.init
  unless repo.exists?
    set_name_and_email
    repo.init!(File.read(GITIGNORE_FILE))
    commit("Add the base system.")
  end
end

.repoObject


35
36
37
38
39
40
# File 'lib/babushka/git_fs.rb', line 35

def self.repo
  # Using :run_as_owner means babushka will sudo to commit to the gitfs when
  # meeting deps as a regular user. For this to work well, the app user
  # should have passwordless sudo during provisioning, revoked on completion.
  @repo ||= Babushka::GitRepo.new(root, :run_as_owner => true)
end

.rootObject


42
43
44
# File 'lib/babushka/git_fs.rb', line 42

def self.root
  '/'.p
end

.set_name_and_emailObject


27
28
29
30
31
32
33
# File 'lib/babushka/git_fs.rb', line 27

def self.set_name_and_email
  if !Babushka::ShellHelpers.shell?("git config --global user.name") ||
     !Babushka::ShellHelpers.shell?("git config --global user.email")
    Babushka::ShellHelpers.shell("git config --global user.name babushka", :as => root.owner)
    Babushka::ShellHelpers.shell("git config --global user.email [email protected]", :as => root.owner)
  end
end

.snapshotting_with(message, &blk) ⇒ Object


5
6
7
8
9
10
11
12
# File 'lib/babushka/git_fs.rb', line 5

def self.snapshotting_with message, &blk
  if Babushka::Base.task.opt(:git_fs)
    init
    blk.call.tap {|result| commit(message) if result }
  else
    blk.call
  end
end