summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2010-04-26 15:59:59 +0200
committerShawn O. Pearce <spearce@spearce.org>2010-05-12 16:05:54 -0700
commita54e0bae687d4a3600fab87b1182d7303f097a92 (patch)
tree4929985684d99b76f81d215ee861526b1c0d3188
parentdc9c5ed88f54b937c837ac91e48555fd834c8789 (diff)
downloadjgit-a54e0bae687d4a3600fab87b1182d7303f097a92.tar.gz
jgit-a54e0bae687d4a3600fab87b1182d7303f097a92.zip
Add commit command to the pgm package
The commit command is added using the new Git class. Currently this supports only the author and commit-message option. Change-Id: I13152575b5b03f6f9e816d0747e7a8c5c6fccade Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
-rw-r--r--org.eclipse.jgit.pgm/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin1
-rw-r--r--org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java85
3 files changed, 88 insertions, 1 deletions
diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
index 4169d263f6..cedc4e8fd8 100644
--- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
+++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF
@@ -6,7 +6,8 @@ Bundle-Version: 0.8.0.qualifier
Bundle-Vendor: %provider_name
Bundle-Localization: plugin
Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Import-Package: org.eclipse.jgit.awtui;version="[0.8.0,0.9.0)",
+Import-Package: org.eclipse.jgit.api;version="[0.8.0,0.9.0)",
+ org.eclipse.jgit.awtui;version="[0.8.0,0.9.0)",
org.eclipse.jgit.diff;version="[0.8.0,0.9.0)",
org.eclipse.jgit.dircache;version="[0.8.0,0.9.0)",
org.eclipse.jgit.errors;version="[0.8.0,0.9.0)",
diff --git a/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin b/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin
index c88711d0e5..0d4a140e62 100644
--- a/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin
+++ b/org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin
@@ -1,6 +1,7 @@
org.eclipse.jgit.pgm.AmazonS3Client
org.eclipse.jgit.pgm.Branch
org.eclipse.jgit.pgm.Clone
+org.eclipse.jgit.pgm.Commit
org.eclipse.jgit.pgm.Daemon
org.eclipse.jgit.pgm.Diff
org.eclipse.jgit.pgm.DiffTree
diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
new file mode 100644
index 0000000000..36e1a73392
--- /dev/null
+++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2010, 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.pgm;
+
+import org.eclipse.jgit.api.CommitCommand;
+import org.eclipse.jgit.api.ConcurrentRefUpdateException;
+import org.eclipse.jgit.api.Git;
+import org.eclipse.jgit.api.JGitInternalException;
+import org.eclipse.jgit.api.NoHeadException;
+import org.eclipse.jgit.api.NoMessageException;
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.PersonIdent;
+import org.eclipse.jgit.lib.Ref;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.kohsuke.args4j.Option;
+
+@Command(common = true, usage = "Record changes to the repository")
+class Commit extends TextBuiltin {
+ // I don't support setting the committer, because also the native git
+ // command doesn't allow this.
+
+ @Option(name = "--author", metaVar="author", usage = "Override the author name used in the commit. You can use the standard A U Thor <author@example.com> format.")
+ private String author;
+
+ @Option(name = "--message", aliases = { "-m" }, metaVar="msg", usage="Use the given <msg> as the commit message", required=true)
+ private String message;
+
+ @Override
+ protected void run() throws NoHeadException, NoMessageException,
+ ConcurrentRefUpdateException, JGitInternalException, Exception {
+ CommitCommand commitCmd = new Git(db).commit();
+ if (author != null)
+ commitCmd.setAuthor(new PersonIdent(author));
+ if (message != null)
+ commitCmd.setMessage(message);
+ Ref head = db.getRef(Constants.HEAD);
+ RevCommit commit = commitCmd.call();
+
+ String branchName;
+ if (!head.isSymbolic())
+ branchName="detached HEAD";
+ else {
+ branchName = head.getTarget().getName();
+ if (branchName.startsWith(Constants.R_HEADS))
+ branchName = branchName.substring(Constants.R_HEADS.length());
+ }
+ out.println("[" + branchName + " " + commit.name() + "] "
+ + commit.getShortMessage());
+ }
+}