tmp-repo
Creates and manages git repositories in the operating system's temporary directory. It does this by providing a thin wrapper around the git binary that's pointed at a randomly generated temporary folder.
Installation
gem install tmp-repo
Usage
require 'tmp-repo'
Basics
Creating a new TmpRepo
will automatically create a randomly named folder in your system's temp directory and initialize a git repository in it:
repo = TmpRepo.new
repo.working_dir
Once created, you can ask your TmpRepo
questions and perform operations on it. Don't forget to clean up after yourself when you're finished:
repo.unlink
Creating Files
repo.create_file('foo.txt') do |f|
f.write("I'm a new file!")
end
OR
file = repo.create_file('foo.txt')
file.write("I'm a new file!")
file.close
Branching
To create a new branch:
repo.create_branch('my_new_branch')
To check out a branch:
repo.checkout('my_other_branch')
To get the current branch:
repo.current_branch
Staging and Committing
To add all files to the git stage:
repo.add_all
To commit staged files:
repo.commit('Commit message')
Repo Status
TmpRepo
instances provide a convenient way to retrieve the status of the repository via the status
method. status
return values are a simple hash of arrays:
status = repo.status
status[:new_file]
status[:deleted]
status[:modified]
Custom Commands
This library only provides wrapper methods around the most common git commands. To run additional git commands, use the git
method:
repo.git('rebase master')
In addition, the lower-level in_repo
method wraps the given block in a Dir.chdir
, meaning the block is executed in the context of the repo's working directory:
repo.in_repo do
`ls`
end
Requirements
No external requirements.
Running Tests
bundle exec rake
should do the trick.
Authors