2 * Copyright 2000-2008 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 import com
.intellij
.openapi
.project
.Project
;
19 import com
.intellij
.openapi
.vcs
.VcsException
;
20 import com
.intellij
.openapi
.vfs
.VirtualFile
;
21 import git4idea
.commands
.GitHandler
;
22 import git4idea
.commands
.GitSimpleHandler
;
23 import org
.jetbrains
.annotations
.NonNls
;
24 import org
.jetbrains
.annotations
.NotNull
;
26 import java
.util
.ArrayList
;
27 import java
.util
.Collection
;
30 * The tag reference object
32 public class GitTag
extends GitReference
{
34 * Prefix for tags ({@value})
36 @NonNls public static final String REFS_TAGS_PREFIX
= "refs/tags/";
41 * @param name the used name
43 public GitTag(@NotNull String name
) {
51 public String
getFullName() {
52 return REFS_TAGS_PREFIX
+ myName
;
56 * List tags for the git root
58 * @param project the context
59 * @param root the git root
60 * @param tags the tag list
61 * @throws VcsException if there is a problem with running git
63 public static void listAsStrings(final Project project
, final VirtualFile root
, final Collection
<String
> tags
) throws VcsException
{
64 GitSimpleHandler handler
= new GitSimpleHandler(project
, root
, GitHandler
.TAG
);
65 handler
.setNoSSH(true);
66 handler
.setSilent(true);
67 handler
.addParameters("-l");
68 for (String line
: handler
.run().split("\n")) {
69 if (line
.length() == 0) {
77 * List tags for the git root
79 * @param project the context
80 * @param root the git root
81 * @param tags the tag list
82 * @throws VcsException if there is a problem with running git
84 public static void list(final Project project
, final VirtualFile root
, final Collection
<?
super GitTag
> tags
) throws VcsException
{
85 ArrayList
<String
> temp
= new ArrayList
<String
>();
86 listAsStrings(project
, root
, temp
);
87 for (String t
: temp
) {
88 tags
.add(new GitTag(t
));