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

Classes: CLI, Error, InvalidParameter, NotARepositoryError, NothingToCommitError, Repo

Constant Summary collapse

VERSION =

Gem version

"0.0.2"

Class Method Summary collapse

Class Method Details

.current_branchObject



93
94
95
# File 'lib/twit.rb', line 93

def self.current_branch
  self.repo.current_branch
end

.discardObject

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



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

def self.discard
  self.repo.discard
end

.include(branch) ⇒ Object



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

def self.include branch
  self.repo.include branch
end

.include_into(branch) ⇒ Object



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

def self.include_into branch
  self.repo.include_into branch
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
34
35
36
37
# File 'lib/twit.rb', line 23

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

  if is_repo? dir
    return
  end

  Dir.chdir dir do
    stdout, stderr, status = Open3.capture3 "git init"
    if status != 0
      raise Error, stderr
    end
  end
  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)


42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/twit.rb', line 42

def self.is_repo? dir = nil
  dir ||= Dir.getwd
  Dir.chdir dir do
    stdout, stderr, status = Open3.capture3 "git status"
    if status != 0
      if /Not a git repository/.match stderr
        return false
      else
        raise Error, stderr
      end
    end
    return true
  end
end

.listObject



88
89
90
# File 'lib/twit.rb', line 88

def self.list
  self.repo.list
end

.nothing_to_commit?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/twit.rb', line 98

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

.open(branch) ⇒ Object



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

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

.save(message) ⇒ Object



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

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

.saveas(branch, message = nil) ⇒ Object



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

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