Class: HGTK::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/hgtk/repo.rb

Overview

A Mercurial repository.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ Repo

Returns a new instance of Repo.

Parameters:

  • kwargs (Hash)

Options Hash (**kwargs):

  • :dir (String?)

    Path to the repository. Current working directory by default.



13
14
15
# File 'lib/hgtk/repo.rb', line 13

def initialize **kwargs
  @dir = kwargs.fetch :dir, Dir.pwd
end

Instance Attribute Details

#dirObject (readonly)

TODO: Swap out for an existing Hg API?



8
9
10
# File 'lib/hgtk/repo.rb', line 8

def dir
  @dir
end

Instance Method Details

#incomingObject

Check for incoming changesets.



28
29
30
31
# File 'lib/hgtk/repo.rb', line 28

def incoming
  repo_check
  command 'incoming'
end

#is_repo?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/hgtk/repo.rb', line 17

def is_repo?
  Dir.exists? "#{@dir}/.hg"
end

#outgoingObject

Check for outgoing changesets.



34
35
36
37
# File 'lib/hgtk/repo.rb', line 34

def outgoing
  repo_check
  command 'outgoing'
end

#pull(update: false) ⇒ Object

Pull incoming changesets.



40
41
42
43
44
45
# File 'lib/hgtk/repo.rb', line 40

def pull update: false
  repo_check
  cmd = 'incoming'
  cmd += ' -u' if update
  command cmd
end

#push(force: false) ⇒ Object

Push outgoing changesets.



48
49
50
51
52
53
# File 'lib/hgtk/repo.rb', line 48

def push force: false
  repo_check
  cmd = 'outgoing'
  cmd += ' -f' if force
  command cmd
end

#statusObject

Check repo status (uncommitted changes).



22
23
24
25
# File 'lib/hgtk/repo.rb', line 22

def status
  repo_check
  command 'st'
end

#syncObject

Synchronize repository by pulling, then pushing.



56
57
58
59
60
# File 'lib/hgtk/repo.rb', line 56

def sync
  repo_check
  pull
  push
end