Browse Source

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>
tags/v0.8.1
Christian Halstrick 14 years ago
parent
commit
a54e0bae68

+ 2
- 1
org.eclipse.jgit.pgm/META-INF/MANIFEST.MF View File

@@ -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)",

+ 1
- 0
org.eclipse.jgit.pgm/META-INF/services/org.eclipse.jgit.pgm.TextBuiltin View File

@@ -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

+ 85
- 0
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Commit.java View File

@@ -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());
}
}

Loading…
Cancel
Save