diff options
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/api')
4 files changed, 51 insertions, 7 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java index 0dc5d5e7f7..847ab0a9a8 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2010, Chris Aniszczyk <caniszczyk@gmail.com> - * Copyright (C) 2011, Matthias Sohn <matthias.sohn@sap.com> and others + * Copyright (C) 2011, 2020 Matthias Sohn <matthias.sohn@sap.com> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -503,6 +503,11 @@ public class CheckoutCommand extends GitCommand<Ref> { editor.add(new PathEdit(path) { @Override public void apply(DirCacheEntry ent) { + if (ent.getStage() != DirCacheEntry.STAGE_0) { + // A checkout on a conflicting file stages the checked + // out file and resolves the conflict. + ent.setStage(DirCacheEntry.STAGE_0); + } ent.setObjectId(blobId); ent.setFileMode(mode); checkoutPath(ent, r, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java index 30d7f9adc4..aba86fc361 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -413,6 +413,10 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> { return null; } + if (idHEAD != null && idHEAD.isSymbolic()) { + return idHEAD.getTarget(); + } + Ref master = result.getAdvertisedRef(Constants.R_HEADS + Constants.MASTER); ObjectId objectId = master != null ? master.getObjectId() : null; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java index 8d427385d4..6a9fbd4f63 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java @@ -9,6 +9,7 @@ */ package org.eclipse.jgit.api; +import static org.eclipse.jgit.lib.Constants.R_REFS; import static org.eclipse.jgit.lib.Constants.R_TAGS; import java.io.IOException; @@ -73,6 +74,11 @@ public class DescribeCommand extends GitCommand<String> { private List<FileNameMatcher> matchers = new ArrayList<>(); /** + * Whether to use all refs in the refs/ namespace + */ + private boolean useAll; + + /** * Whether to use all tags (incl. lightweight) or not. */ private boolean useTags; @@ -153,6 +159,22 @@ public class DescribeCommand extends GitCommand<String> { } /** + * Instead of using only the annotated tags, use any ref found in refs/ + * namespace. This option enables matching any known branch, + * remote-tracking branch, or lightweight tag. + * + * @param all + * <code>true</code> enables matching any ref found in refs/ + * like setting option --all in c git + * @return {@code this} + * @since 5.10 + */ + public DescribeCommand setAll(boolean all) { + this.useAll = all; + return this; + } + + /** * Instead of using only the annotated tags, use any tag found in refs/tags * namespace. This option enables matching lightweight (non-annotated) tags * or not. @@ -186,7 +208,7 @@ public class DescribeCommand extends GitCommand<String> { private String longDescription(Ref tag, int depth, ObjectId tip) throws IOException { return String.format( - "%s-%d-g%s", tag.getName().substring(R_TAGS.length()), //$NON-NLS-1$ + "%s-%d-g%s", formatRefName(tag.getName()), //$NON-NLS-1$ Integer.valueOf(depth), w.getObjectReader().abbreviate(tip) .name()); } @@ -244,8 +266,7 @@ public class DescribeCommand extends GitCommand<String> { for (FileNameMatcher matcher : matchers) { Stream<Ref> m = tags.stream().filter( tag -> { - matcher.append( - tag.getName().substring(R_TAGS.length())); + matcher.append(formatRefName(tag.getName())); boolean result = matcher.isMatch(); matcher.reset(); return result; @@ -283,7 +304,7 @@ public class DescribeCommand extends GitCommand<String> { } Collection<Ref> tagList = repo.getRefDatabase() - .getRefsByPrefix(R_TAGS); + .getRefsByPrefix(useAll ? R_REFS : R_TAGS); Map<ObjectId, List<Ref>> tags = tagList.stream() .filter(this::filterLightweightTags) .collect(Collectors.groupingBy(this::getObjectIdFromRef)); @@ -336,7 +357,7 @@ public class DescribeCommand extends GitCommand<String> { Optional<Ref> bestMatch = getBestMatch(tags.get(target)); if (bestMatch.isPresent()) { return longDesc ? longDescription(bestMatch.get(), 0, target) : - bestMatch.get().getName().substring(R_TAGS.length()); + formatRefName(bestMatch.get().getName()); } w.markStart(target); @@ -408,6 +429,16 @@ public class DescribeCommand extends GitCommand<String> { } /** + * Removes the refs/ or refs/tags prefix from tag names + * @param name the name of the tag + * @return the tag name with its prefix removed + */ + private String formatRefName(String name) { + return name.startsWith(R_TAGS) ? name.substring(R_TAGS.length()) : + name.substring(R_REFS.length()); + } + + /** * Whether we use lightweight tags or not for describe Candidates * * @param ref @@ -419,7 +450,7 @@ public class DescribeCommand extends GitCommand<String> { private boolean filterLightweightTags(Ref ref) { ObjectId id = ref.getObjectId(); try { - return this.useTags || (id != null && (w.parseTag(id) != null)); + return this.useAll || this.useTags || (id != null && (w.parseTag(id) != null)); } catch (IOException e) { return false; } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleDeinitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleDeinitCommand.java index ac17d3a642..f4b8ac2e07 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleDeinitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleDeinitCommand.java @@ -20,8 +20,10 @@ import java.util.Collections; import java.util.List; import org.eclipse.jgit.api.errors.GitAPIException; +import org.eclipse.jgit.api.errors.InvalidConfigurationException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.NoHeadException; +import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.ObjectId; @@ -119,6 +121,8 @@ public class SubmoduleDeinitCommand } } return results; + } catch (ConfigInvalidException e) { + throw new InvalidConfigurationException(e.getMessage(), e); } catch (IOException e) { throw new JGitInternalException(e.getMessage(), e); } |