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' # alternatively, g.refspec = 'ghpages:/refs/heads/ghpages' 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
Methods
public class
public instance
Attributes
branch | [RW] | |
directories | [R] | |
files | [R] | |
gash | [R] | |
message | [RW] | |
push_to | [RW] | |
refspec | [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: if block_given? 79: if blk.arity == 1 80: blk.call(self) 81: else 82: self.instance_eval(&blk) 83: end 84: end 85: end
Public instance methods
# File lib/grancher.rb, line 123 123: def branch=(branch) 124: @refspec = "#{branch}:refs/heads/#{branch}" 125: @branch = branch 126: end
Commits the changes.
# File lib/grancher.rb, line 134 134: def commit(message = nil) 135: build.commit(message || message()) 136: end
Stores the directory from at to.
# File lib/grancher.rb, line 93 93: def directory(from, to = nil) 94: @directories[from.chomp('/')] = to 95: end
Stores the file from at to.
# File lib/grancher.rb, line 98 98: def file(from, to = nil) 99: @files[from] = to 100: end
Returns our Gash-object
# File lib/grancher.rb, line 88 88: def gash 89: @gash ||= Gash.new(@repo, @branch) 90: end
Keeps the files (or directories) given.
# File lib/grancher.rb, line 103 103: def keep(*files) 104: @keep.concat(files.flatten) 105: end
Keep all the files in the branch.
# File lib/grancher.rb, line 108 108: def keep_all 109: @keep_all = true 110: end
Pushes the branch to the remote.
# File lib/grancher.rb, line 129 129: def push 130: gash.send(:git, 'push', @push_to, @refspec) 131: end
Full git refspec to push to. Setting g.refspec will replace g.branch. Used when the remote branch is different to the local branch. Any git refspec is valid (‘man git-push’ for details)
# File lib/grancher.rb, line 114 114: def refspec=(refspec) 115: if refspec =~ /^\+?(.*)(?:\:.*)$/ 116: @branch = $1 117: else 118: raise ArgumentError, "refspec syntax error. Should be: branch:refs/heads/branch" 119: end 120: @refspec = refspec 121: end