Module: Twit

Defined in:
lib/twit.rb,
lib/twit/cli.rb,
lib/twit/repo.rb,
lib/twit/error.rb,
lib/twit/version.rb

Overview

This module exposes twit commands as methods.

Defined Under Namespace

Modules: GUI Classes: CLI, Error, InvalidParameter, NotARepositoryError, NothingToCommitError, Repo, UnsavedChanges

Constant Summary collapse

VERSION =

Gem version

"0.0.3"

Class Method Summary collapse

Class Method Details

.current_branchObject



79
80
81
# File 'lib/twit.rb', line 79

def self.current_branch
  self.repo.current_branch
end

.discardObject

See Twit::Repo#discard. (WARNING: PERMANENTLY DESTROYS DATA!)



59
60
61
# File 'lib/twit.rb', line 59

def self.discard
  self.repo.discard
end

.init(dir = nil) ⇒ Object

Initialize a git repository in a directory. Return a Twit::Repo object representing the new repository.

If no argument is supplied, use the working directory.

If init is called on a directory that is already part of a repository, simply do nothing.



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/twit.rb', line 23

def self.init dir = nil
  dir ||= Dir.getwd

  if is_repo? dir
    return
  end

  Rugged::Repository.init_at(dir)

  Repo.new dir
end

.is_repo?(dir = nil) ⇒ Boolean

Check if a given directory is a git repository.

If no argument is supplied, use the working directory.

Returns:

  • (Boolean)


38
39
40
41
42
43
44
45
46
# File 'lib/twit.rb', line 38

def self.is_repo? dir = nil
  dir ||= Dir.getwd
  begin
    root = Rugged::Repository.discover(dir)
  rescue Rugged::RepositoryError
    return false
  end
  return true
end

.listObject



74
75
76
# File 'lib/twit.rb', line 74

def self.list
  self.repo.list
end

.nothing_to_commit?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/twit.rb', line 84

def self.nothing_to_commit?
  self.repo.nothing_to_commit?
end

.open(branch) ⇒ Object



64
65
66
# File 'lib/twit.rb', line 64

def self.open branch
  self.repo.open branch
end

.repoObject

Get a Repo representing the repository for the current working directory.



12
13
14
# File 'lib/twit.rb', line 12

def self.repo
  Twit::Repo.new
end

.rewind(amount) ⇒ Object



69
70
71
# File 'lib/twit.rb', line 69

def self.rewind amount
  self.repo.rewind amount
end

.save(message) ⇒ Object



49
50
51
# File 'lib/twit.rb', line 49

def self.save message
  self.repo.save message
end

.saveas(branch, message = nil) ⇒ Object



54
55
56
# File 'lib/twit.rb', line 54

def self.saveas branch, message = nil
  self.repo.saveas branch, message
end