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.



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

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

Instance Method Details

#clone(repo) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# 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}")
    when "powerpellet"
        # do nothing
    else
        raise MsPac::Error::UnsupportedVCS.new(@vcs)
    end
end

#ignore_file_perms(name) ⇒ Object



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

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

#revisionObject



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

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

#updateObject



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/mspac/version_control.rb', line 56

def update
    case @vcs
    when "git"
        system("git reset && git pull")
    when "hg"
        system("hg pull && hg update")
    when "powerpellet"
        # do nothing
    else
        raise MsPac::Error::UnsupportedVCS.new(@vcs)
    end
end