diff options
author | Tomasz Zarna <Tomasz.Zarna@pl.ibm.com> | 2012-06-13 23:28:55 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2012-06-15 08:59:41 +0200 |
commit | 2656ac1b5acb9b73c6b47e2cf8830a0a0b2cc214 (patch) | |
tree | 1f48ca5fafef4ae7482c88b2084d532508bb944c /org.eclipse.jgit/src/org/eclipse/jgit/lib | |
parent | c4087af65ddfd976f2a2513a773f50b1fd790336 (diff) | |
download | jgit-2656ac1b5acb9b73c6b47e2cf8830a0a0b2cc214.tar.gz jgit-2656ac1b5acb9b73c6b47e2cf8830a0a0b2cc214.zip |
Add "--squash" option to MergeCommand
CQ: 6570
Bug: 351806
Change-Id: I5e47810376419264ecf4247b5a333af5c8945080
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/lib')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java | 5 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java | 92 |
2 files changed, 70 insertions, 27 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java index 5332ffa711..d5be3157d5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Constants.java @@ -1,7 +1,7 @@ /* * Copyright (C) 2008, Google Inc. * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> - * Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org> + * Copyright (C) 2006-2012, Shawn O. Pearce <spearce@spearce.org> * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -553,6 +553,9 @@ public final class Constants { /** name of the file containing the ID of a cherry pick commit in case of conflicts */ public static final String CHERRY_PICK_HEAD = "CHERRY_PICK_HEAD"; + /** name of the file containing the commit msg for a squash commit */ + public static final String SQUASH_MSG = "SQUASH_MSG"; + /** * name of the ref ORIG_HEAD used by certain commands to store the original * value of HEAD diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index 7b9d453aa2..2c04a74f40 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -2,7 +2,7 @@ * Copyright (C) 2007, Dave Watson <dwatson@mimvista.com> * Copyright (C) 2008-2010, Google Inc. * Copyright (C) 2006-2010, Robin Rosenberg <robin.rosenberg@dewire.com> - * Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org> + * Copyright (C) 2006-2012, Shawn O. Pearce <spearce@spearce.org> * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -1125,24 +1125,14 @@ public abstract class Repository { * See {@link #isBare()}. */ public String readMergeCommitMsg() throws IOException, NoWorkTreeException { - if (isBare() || getDirectory() == null) - throw new NoWorkTreeException(); - - File mergeMsgFile = new File(getDirectory(), Constants.MERGE_MSG); - try { - return RawParseUtils.decode(IO.readFully(mergeMsgFile)); - } catch (FileNotFoundException e) { - // MERGE_MSG file has disappeared in the meantime - // ignore it - return null; - } + return readCommitMsgFile(Constants.MERGE_MSG); } /** * Write new content to the file $GIT_DIR/MERGE_MSG. In this file operations * triggering a merge will store a template for the commit message of the * merge commit. If <code>null</code> is specified as message the file will - * be deleted + * be deleted. * * @param msg * the message which should be written or <code>null</code> to @@ -1152,16 +1142,7 @@ public abstract class Repository { */ public void writeMergeCommitMsg(String msg) throws IOException { File mergeMsgFile = new File(gitDir, Constants.MERGE_MSG); - if (msg != null) { - FileOutputStream fos = new FileOutputStream(mergeMsgFile); - try { - fos.write(msg.getBytes(Constants.CHARACTER_ENCODING)); - } finally { - fos.close(); - } - } else { - FileUtils.delete(mergeMsgFile, FileUtils.SKIP_MISSING); - } + writeCommitMsg(mergeMsgFile, msg); } /** @@ -1169,9 +1150,9 @@ public abstract class Repository { * file operations triggering a merge will store the IDs of all heads which * should be merged together with HEAD. * - * @return a list of commits which IDs are listed in the MERGE_HEAD - * file or {@code null} if this file doesn't exist. Also if the file - * exists but is empty {@code null} will be returned + * @return a list of commits which IDs are listed in the MERGE_HEAD file or + * {@code null} if this file doesn't exist. Also if the file exists + * but is empty {@code null} will be returned * @throws IOException * @throws NoWorkTreeException * if this is bare, which implies it has no working directory. @@ -1281,6 +1262,65 @@ public abstract class Repository { } /** + * Return the information stored in the file $GIT_DIR/SQUASH_MSG. In this + * file operations triggering a squashed merge will store a template for the + * commit message of the squash commit. + * + * @return a String containing the content of the SQUASH_MSG file or + * {@code null} if this file doesn't exist + * @throws IOException + * @throws NoWorkTreeException + * if this is bare, which implies it has no working directory. + * See {@link #isBare()}. + */ + public String readSquashCommitMsg() throws IOException { + return readCommitMsgFile(Constants.SQUASH_MSG); + } + + /** + * Write new content to the file $GIT_DIR/SQUASH_MSG. In this file + * operations triggering a squashed merge will store a template for the + * commit message of the squash commit. If <code>null</code> is specified as + * message the file will be deleted. + * + * @param msg + * the message which should be written or <code>null</code> to + * delete the file + * + * @throws IOException + */ + public void writeSquashCommitMsg(String msg) throws IOException { + File squashMsgFile = new File(gitDir, Constants.SQUASH_MSG); + writeCommitMsg(squashMsgFile, msg); + } + + private String readCommitMsgFile(String msgFilename) throws IOException { + if (isBare() || getDirectory() == null) + throw new NoWorkTreeException(); + + File mergeMsgFile = new File(getDirectory(), msgFilename); + try { + return RawParseUtils.decode(IO.readFully(mergeMsgFile)); + } catch (FileNotFoundException e) { + // the file has disappeared in the meantime ignore it + return null; + } + } + + private void writeCommitMsg(File msgFile, String msg) throws IOException { + if (msg != null) { + FileOutputStream fos = new FileOutputStream(msgFile); + try { + fos.write(msg.getBytes(Constants.CHARACTER_ENCODING)); + } finally { + fos.close(); + } + } else { + FileUtils.delete(msgFile, FileUtils.SKIP_MISSING); + } + } + + /** * Read a file from the git directory. * * @param filename |