Feature #5386 » tags.patch
| app/models/repository/git.rb | ||
|---|---|---|
| 1 |
# -*- coding: utf-8 -*- |
|
| 1 | 2 |
# Redmine - project management software |
| 2 | 3 |
# Copyright (C) 2006-2014 Jean-Philippe Lang |
| 3 | 4 |
# Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com |
| ... | ... | |
| 68 | 69 | |
| 69 | 70 |
# Returns the readable identifier for the given git changeset |
| 70 | 71 |
def self.format_changeset_identifier(changeset) |
| 71 |
changeset.revision[0, 8] |
|
| 72 |
str = changeset.revision[0, 8] |
|
| 73 |
h = changeset.repository.extra_info |
|
| 74 |
unless h.nil? || h['refs'].nil? |
|
| 75 |
ref = h['refs'][changeset.revision.to_s] |
|
| 76 |
str += ' [' + ref.join(', ') + ']' if ref.respond_to?('join')
|
|
| 77 |
end |
|
| 78 |
str |
|
| 72 | 79 |
end |
| 73 | 80 | |
| 74 | 81 |
def branches |
| ... | ... | |
| 79 | 86 |
scm.tags |
| 80 | 87 |
end |
| 81 | 88 | |
| 89 |
def refs |
|
| 90 |
scm.refs |
|
| 91 |
end |
|
| 92 | ||
| 82 | 93 |
def default_branch |
| 83 | 94 |
scm.default_branch |
| 84 | 95 |
rescue Exception => e |
| ... | ... | |
| 130 | 141 |
def fetch_changesets |
| 131 | 142 |
scm_brs = branches |
| 132 | 143 |
return if scm_brs.nil? || scm_brs.empty? |
| 144 |
merge_extra_info('refs' => refs)
|
|
| 145 |
self.save |
|
| 133 | 146 | |
| 134 | 147 |
h1 = extra_info || {}
|
| 135 | 148 |
h = h1.dup |
| lib/redmine/scm/adapters/git_adapter.rb | ||
|---|---|---|
| 1 |
# -*- coding: utf-8 -*- |
|
| 1 | 2 |
# Redmine - project management software |
| 2 | 3 |
# Copyright (C) 2006-2014 Jean-Philippe Lang |
| 3 | 4 |
# |
| ... | ... | |
| 80 | 81 | |
| 81 | 82 |
def branches |
| 82 | 83 |
return @branches if @branches |
| 83 |
@branches = [] |
|
| 84 |
cmd_args = %w|branch --no-color --verbose --no-abbrev| |
|
| 85 |
git_cmd(cmd_args) do |io| |
|
| 86 |
io.each_line do |line| |
|
| 87 |
branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$')
|
|
| 88 |
bran = GitBranch.new(branch_rev[2]) |
|
| 89 |
bran.revision = branch_rev[3] |
|
| 90 |
bran.scmid = branch_rev[3] |
|
| 91 |
bran.is_default = ( branch_rev[1] == '*' ) |
|
| 92 |
@branches << bran |
|
| 93 |
end |
|
| 94 |
end |
|
| 95 |
@branches.sort! |
|
| 96 |
rescue ScmCommandAborted |
|
| 97 |
nil |
|
| 84 |
refs |
|
| 85 |
@branches |
|
| 98 | 86 |
end |
| 99 | 87 | |
| 100 | 88 |
def tags |
| 101 | 89 |
return @tags if @tags |
| 102 |
cmd_args = %w|tag| |
|
| 90 |
refs |
|
| 91 |
@tags |
|
| 92 |
end |
|
| 93 | ||
| 94 |
def refs |
|
| 95 |
return @refs if @refs |
|
| 96 |
cmd_args = %w|show-ref --head --tags --heads --dereference| |
|
| 103 | 97 |
git_cmd(cmd_args) do |io| |
| 104 |
@tags = io.readlines.sort!.map{|t| t.strip}
|
|
| 98 |
head = nil |
|
| 99 |
@refs = {}
|
|
| 100 |
@branches = [] |
|
| 101 |
@tags = [] |
|
| 102 |
io.each do |line| |
|
| 103 |
rev,ref = line.split |
|
| 104 |
if m = ref.match(%r|^HEAD$|) |
|
| 105 |
head = rev |
|
| 106 |
elsif m = ref.match(%r|^refs/heads/(.*)|) |
|
| 107 |
@refs[rev] ||= [] |
|
| 108 |
@refs[rev] << m[1] |
|
| 109 |
b = GitBranch.new(m[1]) |
|
| 110 |
b.revision = rev |
|
| 111 |
b.scmid = rev |
|
| 112 |
b.is_default = false |
|
| 113 |
@branches << b |
|
| 114 |
elsif m = ref.match(%r|^refs/tags/(.*)\^{}$|)
|
|
| 115 |
@refs[rev] ||= [] |
|
| 116 |
@refs[rev] << "tag: #{m[1]}"
|
|
| 117 |
@tags << m[1] |
|
| 118 |
end |
|
| 119 |
end |
|
| 120 |
@branches.sort!.map!{ |b|
|
|
| 121 |
b.is_default = true if b.revision == head |
|
| 122 |
b |
|
| 123 |
} |
|
| 124 |
@tags.sort! |
|
| 105 | 125 |
end |
| 126 |
@refs |
|
| 106 | 127 |
rescue ScmCommandAborted |
| 128 |
@branches = nil |
|
| 129 |
@tags = nil |
|
| 107 | 130 |
nil |
| 108 | 131 |
end |
| 109 | 132 | |