From 1a7c918b66b86c4a629dda6bdbe58a580399b4cc Mon Sep 17 00:00:00 2001 From: Sasa Zivkov Date: Fri, 5 Nov 2010 15:18:00 +0100 Subject: [PATCH] Implemented the git add commandline command. Implementation delegates all work to the AddCommand class and, therefore, supports only those options currently supported by the AddCommand which means: --update and the filepattern... arguments. Change-Id: I4827d37e08b4c988c2458d9ba60a61b6ad414d10 Signed-off-by: Sasa Zivkov --- .../services/org.eclipse.jgit.pgm.TextBuiltin | 1 + .../org/eclipse/jgit/pgm/CLIText.properties | 14 ++-- .../src/org/eclipse/jgit/pgm/Add.java | 71 +++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java 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 d98ed113c..f5d45f0d7 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,3 +1,4 @@ +org.eclipse.jgit.pgm.Add org.eclipse.jgit.pgm.AmazonS3Client org.eclipse.jgit.pgm.Branch org.eclipse.jgit.pgm.Clone diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties index 488cff0b9..c4498c677 100644 --- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties +++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/CLIText.properties @@ -8,13 +8,12 @@ N=N IPZillaPasswordPrompt=IPZilla Password authorInfo=Author: {0} <{1}> averageMSPerRead=average {0} ms/read -branchDetachedHEAD=detached HEAD branchAlreadyExists=branch {0} already exists branchCreatedFrom =branch: Created from {0} +branchDetachedHEAD=detached HEAD branchIsNotAnAncestorOfYourCurrentHEAD=The branch '{0}' is not an ancestor of your current HEAD.\nIf you are sure you want to delete it, run 'jgit branch -D {0}'. branchNotFound=branch '{0}' not found. cacheTreePathInfo="{0}": {1} entries, {2} children -configFileNotFound=configuration file {0} not found cannotBeRenamed={0} cannot be renamed cannotChekoutNoHeadsAdvertisedByRemote=cannot checkout; no HEAD advertised by remote cannotCreateCommand=Cannot create command {0} @@ -33,6 +32,7 @@ cannotWrite=Cannot write {0} cantFindGitDirectory=error: can't find git directory cantWrite=Can't write {0} commitLabel=commit +configFileNotFound=configuration file {0} not found conflictingUsageOf_git_dir_andArguments=conflicting usage of --git-dir and arguments couldNotCreateBranch=Could not create branch {0}: {1} dateInfo=Date: {0} @@ -67,6 +67,7 @@ metaVar_configFile=FILE metaVar_connProp=conn.prop metaVar_directory=DIRECTORY metaVar_file=FILE +metaVar_filepattern=filepattern metaVar_gitDir=GIT_DIR metaVar_hostName=HOSTNAME metaVar_linesOfContext=lines @@ -117,9 +118,9 @@ skippingObject=skipping {0} {1} timeInMilliSeconds={0} ms tooManyRefsGiven=Too many refs given unsupportedOperation=Unsupported operation: {0} +usage_CommandLineClientForamazonsS3Service=Command line client for Amazon's S3 service usage_CommitAuthor=Override the author name used in the commit. You can use the standard A U Thor format. usage_CommitMessage=Use the given as the commit message -usage_CommandLineClientForamazonsS3Service=Command line client for Amazon's S3 service usage_CreateABareRepository=Create a bare repository usage_CreateATag=Create a tag usage_CreateAnEmptyGitRepository=Create an empty git repository @@ -136,6 +137,7 @@ usage_StopTrackingAFile=Stop tracking a file usage_UpdateRemoteRepositoryFromLocalRefs=Update remote repository from local refs usage_abortConnectionIfNoActivity=abort connection if no activity usage_actOnRemoteTrackingBranches=act on remote-tracking branches +usage_addFileContentsToTheIndex=Add file contents to the index usage_alterTheDetailShown=alter the detail shown usage_approveDestructionOfRepository=approve destruction of repository usage_beMoreVerbose=be more verbose @@ -159,6 +161,7 @@ usage_enableTheServiceInAllRepositories=enable the service in all repositories usage_exportRepositoriesOverGit=Export repositories over git:// usage_exportWithoutGitDaemonExportOk=export without git-daemon-export-ok usage_fetchThinPack=fetch thin pack +usage_filesToAddContentFrom=Files to add content from usage_fixAThinPackToBeComplete=fix a thin pack to be complete usage_forEachRefOutput=for-each-ref output usage_forceCreateBranchEvenExists=force create branch even exists @@ -173,18 +176,19 @@ usage_moveRenameABranch=move/rename a branch usage_nameStatus=show only name and status of files usage_noPrefix=do not show any source or destination prefix usage_noRenames=disable rename detection +usage_onlyMatchAgainstAlreadyTrackedFiles=Only match against already tracked files in the index rather than the working tree usage_outputFile=Output file usage_path=path usage_performFsckStyleChecksOnReceive=perform fsck style checks on receive usage_portNumberToListenOn=port number to listen on usage_produceAnEclipseIPLog=Produce an Eclipse IP log usage_pruneStaleTrackingRefs=prune stale tracking refs -usage_recurseIntoSubtrees=recurse into subtrees usage_recordChangesToRepository=Record changes to the repository +usage_recurseIntoSubtrees=recurse into subtrees usage_renameLimit=limit size of rename matrix usage_setTheGitRepositoryToOperateOn=set the git repository to operate on -usage_showRefNamesMatchingCommits=Show ref names matching commits usage_showPatch=display patch +usage_showRefNamesMatchingCommits=Show ref names matching commits usage_srcPrefix=show the source prefix instead of "a/" usage_symbolicVersionForTheProject=Symbolic version for the project usage_synchronizeIPZillaData=Synchronize IPZilla data diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java new file mode 100644 index 000000000..4670b3508 --- /dev/null +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Add.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2010, Sasa Zivkov + * 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 java.util.ArrayList; +import java.util.List; + +import org.eclipse.jgit.api.AddCommand; +import org.eclipse.jgit.api.Git; +import org.kohsuke.args4j.Argument; +import org.kohsuke.args4j.Option; + +@Command(common = true, usage = "usage_addFileContentsToTheIndex") +class Add extends TextBuiltin { + + @Option(name = "--update", aliases = { "-u" }, usage = "usage_onlyMatchAgainstAlreadyTrackedFiles") + private boolean update = false; + + @Argument(required = true, metaVar = "metavar_filepattern", usage = "usage_filesToAddContentFrom") + private List filepatterns = new ArrayList(); + + @Override + protected void run() throws Exception { + AddCommand addCmd = new Git(db).add(); + addCmd.setUpdate(update); + for (String p : filepatterns) + addCmd.addFilepattern(p); + addCmd.call(); + } +}