Module: Autoproj::AutobuildExtensions::Git

Defined in:
lib/autoproj/autobuild_extensions/git.rb

Instance Method Summary collapse

Instance Method Details

#normalize_branch_name(name) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/autoproj/autobuild_extensions/git.rb', line 37

def normalize_branch_name(name)
    if name =~ /^refs\/heads\//
        name
    else
        "refs/heads/#{name}"
    end
end

#pick_from_autoproj_root(package, installation_manifest) ⇒ Object

Reconfigures this importer to use an already existing checkout located in the given autoproj root

Parameters:



10
11
12
13
14
15
16
# File 'lib/autoproj/autobuild_extensions/git.rb', line 10

def pick_from_autoproj_root(package, installation_manifest)
    other_pkg = installation_manifest[package.name]
    return if !other_pkg || !File.directory?(other_pkg.srcdir)

    relocate(other_pkg.srcdir)
    true
end

#snapshot(package, target_dir = nil, only_local: true, exact_state: true) ⇒ Hash

Get version information

Parameters:

  • options (Hash)

    a customizable set of options

Returns:

  • (Hash)

    the snapshot information, in a format that can be used by #relocate



29
30
31
32
33
34
35
# File 'lib/autoproj/autobuild_extensions/git.rb', line 29

def snapshot(package, target_dir = nil, only_local: true, exact_state: true)
    if only_local
        snapshot_local(package, exact_state: exact_state)
    else
        snapshot_against_remote(package, exact_state: exact_state)
    end
end

#snapshot_against_remote(package, options = Hash.new) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/autoproj/autobuild_extensions/git.rb', line 68

def snapshot_against_remote(package, options = Hash.new)
    info = Hash["tag" => nil, "commit" => nil]
    remote_revname = describe_commit_on_remote(package, "HEAD", tags: options[:exact_state])

    case remote_revname
    when /^refs\/heads\/(.*)/
        remote_branch = $1
        if local_branch == remote_branch
            info["branch"] = local_branch
        else
            info["local_branch"] = local_branch
            info["remote_branch"] = remote_branch
        end
    when /^refs\/tags\/(.*)/
        info["tag"] = $1
    else
        info["local_branch"] = local_branch
        info["remote_branch"] = remote_revname
    end

    if options[:exact_state] && !info["tag"]
        info["commit"] = rev_parse(package, "HEAD")
    end
    info
end

#snapshot_local(package, options = Hash.new) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/autoproj/autobuild_extensions/git.rb', line 95

def snapshot_local(package, options = Hash.new)
    info = Hash.new
    if local_branch == remote_branch
        info["branch"] = branch
    else
        info["local_branch"] = local_branch
        info["remote_branch"] = remote_branch
    end

    if options[:exact_state]
        has_tag, described = describe_rev(package, "HEAD")
        if has_tag
            info["tag"] = described
            info["commit"] = nil
        else
            info["tag"] = nil
            info["commit"] = described
        end
    end
    info
end

#snapshot_overrides?(snapshot) ⇒ Boolean

Returns true if the given snapshot information is different from the configured importer state

It tests only against the parameters returned by #snapshot

Returns:

  • (Boolean)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/autoproj/autobuild_extensions/git.rb', line 49

def snapshot_overrides?(snapshot)
    # We have to normalize the branch and tag names
    if (snapshot_local = snapshot["local_branch"] || snapshot["branch"])
        snapshot_local = normalize_branch_name(snapshot_local)
        local_branch = normalize_branch_name(self.local_branch)
        return true if snapshot_local != local_branch
    end
    if (snapshot_remote = snapshot["remote_branch"] || snapshot["branch"])
        snapshot_remote = normalize_branch_name(snapshot_remote)
        remote_branch  = normalize_branch_name(self.remote_branch)
        return true if snapshot_remote != remote_branch
    end
    if (snapshot_id = snapshot["commit"])
        return true if commit != snapshot_id
    end
    false
end