class Jekyll::Repository

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

Attributes

git[R]
path[R]
site[R]

Public Class Methods

new(site) click to toggle source
   # File lib/jekyll/repository.rb
 9 def initialize(site)
10   require 'rugged'
11 
12   @site = site
13   @path = site.source
14   @git  = Rugged::Repository.new(path)
15 end

Public Instance Methods

commit(message, author = jekyll_author) click to toggle source

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.

@param [String] Commit message @param [Hash] Author @return [String] Commit hash

   # File lib/jekyll/repository.rb
25 def commit(message, author = jekyll_author)
26   site.staged_files.each do |file|
27     git.index.add(real_path file)
28   end
29 
30   git.index.write
31 
32   Rugged::Commit.create(git, message: message, update_ref: 'HEAD',
33                              parents: [git.head.target],
34                              tree: git.index.write_tree,
35                              author: author,
36                              committer: author)
37 end
jekyll_author() click to toggle source
   # File lib/jekyll/repository.rb
39 def jekyll_author
40   @jekyll_author ||= { name: 'Jekyll', email: 'jekyll@localhost', time: Time.now }
41 end

Private Instance Methods

real_path(file) click to toggle source

Find file's real path, relative to site.

   # File lib/jekyll/repository.rb
46 def real_path(file)
47   Pathname.new(file).realpath.relative_path_from(path).to_s
48 end