What is Grancher?
With Grancher you can easily copy folders and files to a Git branch.
How?
As a library
require 'grancher' grancher = Grancher.new do |g| g.branch = 'gh-pages' g.push_to = 'origin' g.repo = 'some_repo' # defaults to '.' g.message = 'Updated website' # defaults to 'Updated files.' # Put the website-directory in the root g.directory 'website' # doc -> doc g.directory 'doc', 'doc' # README -> README g.file 'README' # AUTHORS -> authors.txt g.file 'AUTHORS', 'authors.txt' # CHANGELOG -> doc/CHANGELOG g.file 'CHANGELOG', 'doc/' end grancher.commit grancher.push
As a Raketask
Instead of:
require 'grancher' Grancher.new do |g| ... end
Do:
require 'grancher/task' Grancher::Task.new do |g| ... end
See Grancher::Task for more information.
Keeping the files already in the branch
By default, Grancher will remove any files already in the branch. Use keep and keep_all to change this behaviour:
Grancher.new do |g| # Only keep some files/folders: g.keep 'index.html', 'test', 'lib/grancer' # Keep all the files in the repo: g.keep_all end
Attributes
| branch | [RW] | |
| directories | [R] | |
| files | [R] | |
| gash | [R] | |
| message | [RW] | |
| push_to | [RW] | |
| repo | [RW] |
Public class methods
# File lib/grancher.rb, line 72 72: def initialize(&blk) 73: @directories = {} 74: @files = {} 75: @keep = [] 76: @repo = '.' 77: @message = 'Updated files.' 78: 79: if blk.arity == 1 80: blk.call(self) 81: else 82: self.instance_eval(&blk) 83: end 84: end
Public instance methods
Commits the changes.
# File lib/grancher.rb, line 117 117: def commit(message = nil) 118: build.commit(message || message()) 119: end
Stores the directory from at to.
# File lib/grancher.rb, line 92 92: def directory(from, to = nil) 93: @directories[from.chomp('/')] = to 94: end
Stores the file from at to.
# File lib/grancher.rb, line 97 97: def file(from, to = nil) 98: @files[from] = to 99: end
Returns our Gash-object
# File lib/grancher.rb, line 87 87: def gash 88: @gash ||= Gash.new(@repo, @branch) 89: end
Keeps the files (or directories) given.
# File lib/grancher.rb, line 102 102: def keep(*files) 103: @keep.concat(files) 104: end
Keep all the files in the branch.
# File lib/grancher.rb, line 107 107: def keep_all 108: @keep_all = true 109: end
Pushes the branch to the remote.
# File lib/grancher.rb, line 112 112: def push 113: gash.send(:git, 'push', @push_to, @branch + ':refs/heads/' + @branch) 114: end