Class: MsPac::VersionControl

Inherits:
Object
  • Object
show all
Defined in:
lib/mspac/version_control.rb

Instance Method Summary collapse

Constructor Details

#initialize(vcs) ⇒ VersionControl

Returns a new instance of VersionControl.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/mspac/version_control.rb', line 26

def initialize(vcs)
    case vcs
    when "bzr"
        raise Error::UnsupportedVCSError.new(vcs)
    when "git"
        @vcs = vcs
    when "hg"
        @vcs = vcs
    when "svn"
        raise Error::UnsupportedVCSError.new(vcs)
    else
        raise Error::UnsupportedVCSError.new
    end
end

Instance Method Details

#clone(repo) ⇒ Object



2
3
4
5
6
7
8
9
10
11
# File 'lib/mspac/version_control.rb', line 2

def clone(repo)
    return if (repo.nil? || repo.empty?)

    case @vcs
    when "git", "hg"
        system("#{@vcs} clone #{repo}")
    else
        raise Error::UnsupportedVCSError.new(@vcs)
    end
end

#ignore_file_perms(name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mspac/version_control.rb', line 13

def ignore_file_perms(name)
    Dir.chdir(name) do
        case @vcs
        when "git"
            system("git config core.filemode false")
        when "hg"
            # do nothing
        else
            raise Error::UnsupportedVCSError.new(@vcs)
        end
    end
end

#revisionObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/mspac/version_control.rb', line 41

def revision
    case @vcs
    when "git"
        %x(git log --oneline | head -n 1 | awk '{print $1}')
    when "hg"
        %(hg tip --template "{node}")
    else
        raise Error::UnsupportedVCSError.new(@vcs)
    end
end

#updateObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/mspac/version_control.rb', line 52

def update
    case @vcs
    when "git"
        system("git reset && git pull")
    when "hg"
        system("hg pull && hg update")
    else
        raise Error::UnsupportedVCSError.new(@vcs)
    end
end