diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2013-12-13 12:55:50 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2013-12-13 12:55:59 +0100 |
commit | aad7dee3ef492e9333581e8d6b2269dc091ea1d2 (patch) | |
tree | 276dd2a8f436659bd211535d46959db7cfbee4c4 /org.eclipse.jgit | |
parent | b14a93971837610156e815ae2eee3baaa5b7a44b (diff) | |
parent | 0ce61caefbcada30fb1cc4f3b037560f1ba4a8b7 (diff) | |
download | jgit-aad7dee3ef492e9333581e8d6b2269dc091ea1d2.tar.gz jgit-aad7dee3ef492e9333581e8d6b2269dc091ea1d2.zip |
Merge branch 'stable-3.2'
* stable-3.2:
Canonicalize worktree path in BaseRepositoryBuilder if set via config
Add missing @since tags for new public methods in Config
Don't use API exception in RebaseTodoLine
Fix aborting rebase with detached head
Add recursive variant of Config.getNames() methods
Prepare post 3.2.0-m3 builds
JGit v3.2.0.201311130903-m3
Change-Id: Iad6e284e0fe2c7950f156372b334e47ebd82f3f7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
6 files changed, 129 insertions, 22 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java index 10b273a744..ac6f5487a1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java @@ -1101,24 +1101,29 @@ public class RebaseCommand extends GitCommand<RebaseResult> { } try { String headName = rebaseState.readFile(HEAD_NAME); - if (headName.startsWith(Constants.R_REFS)) { monitor.beginTask(MessageFormat.format( JGitText.get().resettingHead, headName), ProgressMonitor.UNKNOWN); + Result res = null; + RefUpdate refUpdate = repo.updateRef(Constants.HEAD, false); + refUpdate.setRefLogMessage("rebase: aborting", false); //$NON-NLS-1$ + if (headName.startsWith(Constants.R_REFS)) { // update the HEAD - RefUpdate refUpdate = repo.updateRef(Constants.HEAD, false); - refUpdate.setRefLogMessage("rebase: aborting", false); //$NON-NLS-1$ - Result res = refUpdate.link(headName); - switch (res) { - case FAST_FORWARD: - case FORCED: - case NO_CHANGE: - break; - default: - throw new JGitInternalException( - JGitText.get().abortingRebaseFailed); - } + res = refUpdate.link(headName); + } else { + refUpdate.setNewObjectId(repo.readOrigHead()); + res = refUpdate.forceUpdate(); + + } + switch (res) { + case FAST_FORWARD: + case FORCED: + case NO_CHANGE: + break; + default: + throw new JGitInternalException( + JGitText.get().abortingRebaseFailed); } boolean stashConflicts = autoStashApply(); // cleanup the files diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java b/org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java new file mode 100644 index 0000000000..dae150ce0a --- /dev/null +++ b/org.eclipse.jgit/src/org/eclipse/jgit/errors/IllegalTodoFileModification.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2013, Christian Halstrick <christian.halstrick@sap.com> + * and other copyright owners as documented in the project's IP log. + * + * This program and the accompanying materials are made available + * under the terms of the Eclipse Distribution License v1.0 which + * accompanies this distribution, is reproduced below, and is + * available at http://www.eclipse.org/org/documents/edl-v10.php + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Eclipse Foundation, Inc. nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package org.eclipse.jgit.errors; + +/** + * Attempt to modify a rebase-todo file in an unsupported way + * + * @since 3.2 + */ +public class IllegalTodoFileModification extends Exception { + private static final long serialVersionUID = 1L; + + /** + * @param msg + */ + public IllegalTodoFileModification(final String msg) { + super(msg); + } +} diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java index db622f319d..7a6ddb39a1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/BaseRepositoryBuilder.java @@ -695,7 +695,7 @@ public class BaseRepositoryBuilder<B extends BaseRepositoryBuilder, R extends Re String path = cfg.getString(CONFIG_CORE_SECTION, null, CONFIG_KEY_WORKTREE); if (path != null) - return safeFS().resolve(getGitDir(), path); + return safeFS().resolve(getGitDir(), path).getCanonicalFile(); // If core.bare is set, honor its value. Assume workTree is // the parent directory of the repository. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java index 81977d74ac..22337e8131 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Config.java @@ -528,6 +528,35 @@ public class Config { } /** + * @param section + * the section + * @param recursive + * if {@code true} recursively adds the names defined in all base + * configurations + * @return the list of names defined for this section + * @since 3.2 + */ + public Set<String> getNames(String section, boolean recursive) { + return getState().getNames(section, null, recursive); + } + + /** + * @param section + * the section + * @param subsection + * the subsection + * @param recursive + * if {@code true} recursively adds the names defined in all base + * configurations + * @return the list of names defined for this subsection + * @since 3.2 + */ + public Set<String> getNames(String section, String subsection, + boolean recursive) { + return getState().getNames(section, subsection, recursive); + } + + /** * Obtain a handle to a parsed set of configuration values. * * @param <T> diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigSnapshot.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigSnapshot.java index b7c4c64321..5ed129ed02 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigSnapshot.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/ConfigSnapshot.java @@ -97,6 +97,16 @@ class ConfigSnapshot { } Set<String> getNames(String section, String subsection) { + return getNames(section, subsection, false); + } + + Set<String> getNames(String section, String subsection, boolean recursive) { + Map<String, String> m = getNamesInternal(section, subsection, recursive); + return new CaseFoldingSet(m); + } + + private Map<String, String> getNamesInternal(String section, + String subsection, boolean recursive) { List<ConfigLine> s = sorted(); int idx = find(s, section, subsection, ""); //$NON-NLS-1$ if (idx < 0) @@ -113,7 +123,9 @@ class ConfigSnapshot { if (!m.containsKey(l)) m.put(l, e.name); } - return new CaseFoldingSet(m); + if (recursive && baseState != null) + m.putAll(baseState.getNamesInternal(section, subsection, recursive)); + return m; } String[] get(String section, String subsection, String name) { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoLine.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoLine.java index 3aa331c72c..9af8d76910 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoLine.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/RebaseTodoLine.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.lib; import java.text.MessageFormat; -import org.eclipse.jgit.api.errors.JGitInternalException; +import org.eclipse.jgit.errors.IllegalTodoFileModification; import org.eclipse.jgit.internal.JGitText; /** @@ -111,7 +111,7 @@ public class RebaseTodoLine { || action.shortToken.equals(token)) return action; } - throw new JGitInternalException(MessageFormat.format( + throw new IllegalArgumentException(MessageFormat.format( JGitText.get().unknownOrUnsupportedCommand, token, Action.values())); } @@ -167,8 +167,11 @@ public class RebaseTodoLine { * non-comment. * * @param newAction + * @throws IllegalTodoFileModification + * on attempt to set a non-comment action on a line which was a + * comment line before. */ - public void setAction(Action newAction) { + public void setAction(Action newAction) throws IllegalTodoFileModification { if (!Action.COMMENT.equals(action) && Action.COMMENT.equals(newAction)) { // transforming from non-comment to comment if (comment == null) @@ -180,7 +183,7 @@ public class RebaseTodoLine { } else if (Action.COMMENT.equals(action) && !Action.COMMENT.equals(newAction)) { // transforming from comment to non-comment if (commit == null) - throw new JGitInternalException(MessageFormat.format( + throw new IllegalTodoFileModification(MessageFormat.format( JGitText.get().cannotChangeActionOnComment, action, newAction)); } @@ -219,12 +222,11 @@ public class RebaseTodoLine { throw createInvalidCommentException(newComment); } - private static JGitInternalException createInvalidCommentException( + private static IllegalArgumentException createInvalidCommentException( String newComment) { - IllegalArgumentException iae = new IllegalArgumentException( + return new IllegalArgumentException( MessageFormat.format( JGitText.get().argumentIsNotAValidCommentString, newComment)); - return new JGitInternalException(iae.getMessage(), iae); } /** |