Class: BuildTool::VCS::Git

Inherits:
Base show all
Defined in:
lib/kde-build/vcs/git.rb

Overview

Implementation for the git-svn version control system (git-scm.org)

Instance Attribute Summary

Attributes inherited from Base

#configuration, #path, #repository

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, path) ⇒ Git

Returns a new instance of Git.



31
32
33
# File 'lib/kde-build/vcs/git.rb', line 31

def initialize( repository, path )
    super
end

Class Method Details

.configObject



47
48
49
# File 'lib/kde-build/vcs/git.rb', line 47

def self.config
    GitConfiguration
end

Instance Method Details

#checkedout?Boolean

Check if the local checkout exists.

calls VCS::Base::checkedout? and checks if there is a ‘.git’ directory at path

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
# File 'lib/kde-build/vcs/git.rb', line 55

def checkedout?
    return false if !super
    if !File.exists? "#{path}/.git"
        $log.debug("Checkout path #{path} is not a git repo")
        return false
    end
    return true
end

#fetchObject

Fetch from repository

Initializes the local clone if it does not exist.



67
68
69
70
71
72
73
74
75
# File 'lib/kde-build/vcs/git.rb', line 67

def fetch()
    if !checkedout? and !$noop
        init
    end
    cmd = "fetch"
    if ( rc = git( cmd ) ) != 0
        raise GitError, "Error while fetching: #{rc}"
    end
end

#git(command, wd = path) ⇒ Object



39
40
41
# File 'lib/kde-build/vcs/git.rb', line 39

def git( command, wd = path )
    self.class.execute "git #{command}", wd
end

#infoObject



108
109
110
111
# File 'lib/kde-build/vcs/git.rb', line 108

def info
    super
    puts "  Remote Branch:       #{remote_branch.inspect}"
end

#initObject

Initialize the local repository



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/kde-build/vcs/git.rb', line 79

def init
    # Check if path exists
    if File.exists? path
        raise GitSvnError, "Failed to create repository at '#{path}': Path exists"
    end

    # Create the directory
    FileUtils.mkdir_p( File.split(path)[0] ) if !$noop

    # Initialize the repository
    if !git( "clone --no-checkout #{repository} #{path}", Pathname.new(path).dirname )
        raise GitError, "Error while initializing the repo `git clone --no-checkout '#{repository} #{path}'`: #{$?}"
    end

    # Create the local checkout
    if remote_branch != "master"
        if !git( "checkout --track -b #{remote_branch} origin/#{remote_branch}", path )
            raise GitError, "Error while initializing the repo `checkout --track -b '#{remote_branch} origin/#{remote_branch}'`: #{$?}"
        end
    else
        if !git( "checkout #{remote_branch}", path )
            raise GitError, "Error while initializing the repo `git checkout #{remote_branch}'`: #{$?}"
        end
    end


    fetch()
end

#nameObject



35
36
37
# File 'lib/kde-build/vcs/git.rb', line 35

def name
    "GIT"
end

#rebaseObject



113
114
115
# File 'lib/kde-build/vcs/git.rb', line 113

def rebase
    return git "rebase origin"
end

#remote_branchObject



43
44
45
# File 'lib/kde-build/vcs/git.rb', line 43

def remote_branch
    @configuration.remote_branch
end