Class Grancher

  1. lib/grancher/task.rb
  2. lib/grancher.rb
  3. show all
Parent: Object

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

  1. new

public instance

  1. branch=
  2. commit
  3. directory
  4. file
  5. gash
  6. keep
  7. keep_all
  8. push
  9. refspec=

Classes and Modules

Class Grancher::Task

Attributes

branch [RW]
directories [R]
files [R]
gash [R]
message [RW]
push_to [RW]
refspec [RW]
repo [RW]

Public class methods

new (&blk)
[show source]
    # 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

branch= (branch)
[show source]
     # File lib/grancher.rb, line 123
123:   def branch=(branch)
124:     @refspec = "#{branch}:refs/heads/#{branch}"
125:     @branch = branch
126:   end
commit (message = nil)

Commits the changes.

[show source]
     # File lib/grancher.rb, line 134
134:   def commit(message = nil)
135:     build.commit(message || message())
136:   end
directory (from, to = nil)

Stores the directory from at to.

[show source]
    # File lib/grancher.rb, line 93
93:   def directory(from, to = nil)
94:     @directories[from.chomp('/')] = to
95:   end
file (from, to = nil)

Stores the file from at to.

[show source]
     # File lib/grancher.rb, line 98
 98:   def file(from, to = nil)
 99:     @files[from] = to
100:   end
gash ()

Returns our Gash-object

[show source]
    # File lib/grancher.rb, line 88
88:   def gash
89:     @gash ||= Gash.new(@repo, @branch)
90:   end
keep (*files)

Keeps the files (or directories) given.

[show source]
     # File lib/grancher.rb, line 103
103:   def keep(*files)
104:     @keep.concat(files.flatten)
105:   end
keep_all ()

Keep all the files in the branch.

[show source]
     # File lib/grancher.rb, line 108
108:   def keep_all
109:     @keep_all = true
110:   end
push ()

Pushes the branch to the remote.

[show source]
     # File lib/grancher.rb, line 129
129:   def push
130:     gash.send(:git, 'push', @push_to, @refspec)
131:   end
refspec= (refspec)

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)

[show source]
     # 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