Class: Jekyll::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/jekyll/repository.rb

Overview

Super basic access to the Git repository, only useful for commiting changes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(site) ⇒ Repository

Returns a new instance of Repository.



9
10
11
12
13
14
15
# File 'lib/jekyll/repository.rb', line 9

def initialize(site)
  require 'rugged'

  @site = site
  @path = site.source
  @git  = Rugged::Repository.new(path)
end

Instance Attribute Details

#gitObject (readonly)

Returns the value of attribute git.



7
8
9
# File 'lib/jekyll/repository.rb', line 7

def git
  @git
end

#pathObject (readonly)

Returns the value of attribute path.



7
8
9
# File 'lib/jekyll/repository.rb', line 7

def path
  @path
end

#siteObject (readonly)

Returns the value of attribute site.



7
8
9
# File 'lib/jekyll/repository.rb', line 7

def site
  @site
end

Instance Method Details

#commit(message, author = jekyll_author) ⇒ String

Commit changes to repository, first add files to the commit index, then write changes to reflect the current state (otherwise the file will be commited but missing from disk (?)) and then create a commit.

Parameters:

  • Commit (String)

    message

  • Author (Hash)

Returns:

  • (String)

    Commit hash



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

def commit(message, author = jekyll_author)
  site.staged_files.each do |file|
    git.index.add(real_path file)
  end

  git.index.write

  Rugged::Commit.create(git, message: message, update_ref: 'HEAD',
                             parents: [git.head.target],
                             tree: git.index.write_tree,
                             author: author,
                             committer: author)
end

#jekyll_authorObject



39
40
41
# File 'lib/jekyll/repository.rb', line 39

def jekyll_author
  @jekyll_author ||= { name: 'Jekyll', email: 'jekyll@localhost', time: Time.now }
end