diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2014-12-24 01:08:58 +0100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2014-12-24 01:09:25 +0100 |
commit | 988291581034075fab20bbd76147cbc9ad08151b (patch) | |
tree | 313e9e0dca107ba1eba79615e9e0ffb71749f2e3 /org.eclipse.jgit.pgm | |
parent | 90cccb96d2e215c633efa2b06cdd73fca9951489 (diff) | |
parent | 02b0660b8b749b078fc58f135d14206ebad98ad9 (diff) | |
download | jgit-988291581034075fab20bbd76147cbc9ad08151b.tar.gz jgit-988291581034075fab20bbd76147cbc9ad08151b.zip |
Merge branch 'stable-3.6'
* stable-3.6:
Prepare 3.6.1-SNAPSHOT builds
JGit v3.6.0.201412230720-r
[pgm] Add option --bare to clone command
[pgm] Implement clone using CloneCommand
Fix junit tests under windows when the platform is explicitly changed
Fix unit tests for windows by explicitly closing test repos
[pgm] Add option --tags for ls-remote
[pgm] Add option --heads for ls-remote
[pgm] Use LsRemoteCommand to implement ls-remote and add a test
Change-Id: I8f31e76cb7e9416919f37e02c7e51ab1d221df40
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm')
7 files changed, 96 insertions, 170 deletions
diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF index e4628b0222..cb2e422b29 100644 --- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF @@ -2,43 +2,43 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.pgm -Bundle-Version: 3.6.0.qualifier +Bundle-Version: 3.6.1.qualifier Bundle-Vendor: %provider_name Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: org.apache.commons.compress.archivers;version="[1.3,2.0)", org.apache.commons.compress.archivers.tar;version="[1.3,2.0)", org.apache.commons.compress.archivers.zip;version="[1.3,2.0)", - org.eclipse.jgit.api;version="[3.6.0,3.7.0)", - org.eclipse.jgit.api.errors;version="[3.6.0,3.7.0)", - org.eclipse.jgit.archive;version="[3.6.0,3.7.0)", - org.eclipse.jgit.awtui;version="[3.6.0,3.7.0)", - org.eclipse.jgit.blame;version="[3.6.0,3.7.0)", - org.eclipse.jgit.diff;version="[3.6.0,3.7.0)", - org.eclipse.jgit.dircache;version="[3.6.0,3.7.0)", - org.eclipse.jgit.errors;version="[3.6.0,3.7.0)", - org.eclipse.jgit.gitrepo;version="[3.6.0,3.7.0)", - org.eclipse.jgit.internal.storage.file;version="[3.6.0,3.7.0)", - org.eclipse.jgit.internal.storage.pack;version="[3.6.0,3.7.0)", - org.eclipse.jgit.lib;version="[3.6.0,3.7.0)", - org.eclipse.jgit.merge;version="3.6.0", - org.eclipse.jgit.nls;version="[3.6.0,3.7.0)", - org.eclipse.jgit.notes;version="[3.6.0,3.7.0)", - org.eclipse.jgit.revplot;version="[3.6.0,3.7.0)", - org.eclipse.jgit.revwalk;version="[3.6.0,3.7.0)", - org.eclipse.jgit.revwalk.filter;version="[3.6.0,3.7.0)", - org.eclipse.jgit.storage.file;version="[3.6.0,3.7.0)", - org.eclipse.jgit.storage.pack;version="[3.6.0,3.7.0)", - org.eclipse.jgit.transport;version="[3.6.0,3.7.0)", - org.eclipse.jgit.transport.resolver;version="[3.6.0,3.7.0)", - org.eclipse.jgit.treewalk;version="[3.6.0,3.7.0)", - org.eclipse.jgit.treewalk.filter;version="[3.6.0,3.7.0)", - org.eclipse.jgit.util;version="[3.6.0,3.7.0)", - org.eclipse.jgit.util.io;version="[3.6.0,3.7.0)", + org.eclipse.jgit.api;version="[3.6.1,3.7.0)", + org.eclipse.jgit.api.errors;version="[3.6.1,3.7.0)", + org.eclipse.jgit.archive;version="[3.6.1,3.7.0)", + org.eclipse.jgit.awtui;version="[3.6.1,3.7.0)", + org.eclipse.jgit.blame;version="[3.6.1,3.7.0)", + org.eclipse.jgit.diff;version="[3.6.1,3.7.0)", + org.eclipse.jgit.dircache;version="[3.6.1,3.7.0)", + org.eclipse.jgit.errors;version="[3.6.1,3.7.0)", + org.eclipse.jgit.gitrepo;version="[3.6.1,3.7.0)", + org.eclipse.jgit.internal.storage.file;version="[3.6.1,3.7.0)", + org.eclipse.jgit.internal.storage.pack;version="[3.6.1,3.7.0)", + org.eclipse.jgit.lib;version="[3.6.1,3.7.0)", + org.eclipse.jgit.merge;version="3.6.1", + org.eclipse.jgit.nls;version="[3.6.1,3.7.0)", + org.eclipse.jgit.notes;version="[3.6.1,3.7.0)", + org.eclipse.jgit.revplot;version="[3.6.1,3.7.0)", + org.eclipse.jgit.revwalk;version="[3.6.1,3.7.0)", + org.eclipse.jgit.revwalk.filter;version="[3.6.1,3.7.0)", + org.eclipse.jgit.storage.file;version="[3.6.1,3.7.0)", + org.eclipse.jgit.storage.pack;version="[3.6.1,3.7.0)", + org.eclipse.jgit.transport;version="[3.6.1,3.7.0)", + org.eclipse.jgit.transport.resolver;version="[3.6.1,3.7.0)", + org.eclipse.jgit.treewalk;version="[3.6.1,3.7.0)", + org.eclipse.jgit.treewalk.filter;version="[3.6.1,3.7.0)", + org.eclipse.jgit.util;version="[3.6.1,3.7.0)", + org.eclipse.jgit.util.io;version="[3.6.1,3.7.0)", org.kohsuke.args4j;version="[2.0.12,2.1.0)", org.kohsuke.args4j.spi;version="[2.0.12,2.1.0)" Bundle-ActivationPolicy: lazy -Export-Package: org.eclipse.jgit.pgm;version="3.6.0"; +Export-Package: org.eclipse.jgit.pgm;version="3.6.1"; uses:="org.eclipse.jgit.revwalk, org.eclipse.jgit.treewalk.filter, org.eclipse.jgit.pgm.opt, @@ -49,10 +49,10 @@ Export-Package: org.eclipse.jgit.pgm;version="3.6.0"; org.eclipse.jgit.treewalk, javax.swing, org.eclipse.jgit.transport", - org.eclipse.jgit.pgm.debug;version="3.6.0"; + org.eclipse.jgit.pgm.debug;version="3.6.1"; uses:="org.eclipse.jgit.pgm", - org.eclipse.jgit.pgm.internal;version="3.6.0";x-friends:="org.eclipse.jgit.pgm.test,org.eclipse.jgit.test", - org.eclipse.jgit.pgm.opt;version="3.6.0"; + org.eclipse.jgit.pgm.internal;version="3.6.1";x-friends:="org.eclipse.jgit.pgm.test,org.eclipse.jgit.test", + org.eclipse.jgit.pgm.opt;version="3.6.1"; uses:="org.eclipse.jgit.lib, org.eclipse.jgit.revwalk, org.kohsuke.args4j.spi, diff --git a/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF index 29bcf8e3af..198bffd1a6 100644 --- a/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF +++ b/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF @@ -3,5 +3,5 @@ Bundle-ManifestVersion: 2 Bundle-Name: org.eclipse.jgit.pgm - Sources Bundle-SymbolicName: org.eclipse.jgit.pgm.source Bundle-Vendor: Eclipse.org - JGit -Bundle-Version: 3.6.0.qualifier -Eclipse-SourceBundle: org.eclipse.jgit.pgm;version="3.6.0.qualifier";roots="." +Bundle-Version: 3.6.1.qualifier +Eclipse-SourceBundle: org.eclipse.jgit.pgm;version="3.6.1.qualifier";roots="." diff --git a/org.eclipse.jgit.pgm/pom.xml b/org.eclipse.jgit.pgm/pom.xml index 2c2a3aab47..2d6ed7afdb 100644 --- a/org.eclipse.jgit.pgm/pom.xml +++ b/org.eclipse.jgit.pgm/pom.xml @@ -50,7 +50,7 @@ <parent> <groupId>org.eclipse.jgit</groupId> <artifactId>org.eclipse.jgit-parent</artifactId> - <version>3.6.0-SNAPSHOT</version> + <version>3.6.1-SNAPSHOT</version> </parent> <artifactId>org.eclipse.jgit.pgm</artifactId> diff --git a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties index bdf05e901a..c0ecc8391c 100644 --- a/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties +++ b/org.eclipse.jgit.pgm/resources/org/eclipse/jgit/pgm/internal/CLIText.properties @@ -43,6 +43,8 @@ changesNotStagedForCommit=Changes not staged for commit: changesToBeCommitted=Changes to be committed: checkoutConflict=error: Your local changes to the following files would be overwritten by checkout: checkoutConflictPathLine=\t{0} +clonedEmptyRepository=warning: You appear to have cloned an empty repository. +cloningInto=Cloning into ''{0}''... commitLabel=commit configFileNotFound=configuration file {0} not found conflictingUsageOf_git_dir_andArguments=conflicting usage of --git-dir and arguments @@ -203,6 +205,8 @@ usage_Gc=Cleanup unnecessary files and optimize the local repository usage_Glog=View commit history as a graph usage_IndexPack=Build pack index file for an existing packed archive usage_LsRemote=List references in a remote repository +usage_lsRemoteHeads=Show only refs starting with refs/heads +usage_lsRemoteTags=Show only refs starting with refs/tags usage_LsTree=List the contents of a tree object usage_MakeCacheTree=Show the current cache tree structure usage_MergeBase=Find as good common ancestors as possible for a merge diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java index d9a877cd67..cd6953cb05 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java @@ -44,30 +44,15 @@ package org.eclipse.jgit.pgm; import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; import java.text.MessageFormat; -import org.eclipse.jgit.dircache.DirCache; -import org.eclipse.jgit.dircache.DirCacheCheckout; -import org.eclipse.jgit.errors.IncorrectObjectTypeException; -import org.eclipse.jgit.errors.MissingObjectException; +import org.eclipse.jgit.api.CloneCommand; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.lib.Ref; -import org.eclipse.jgit.lib.RefUpdate; -import org.eclipse.jgit.lib.Repository; -import org.eclipse.jgit.lib.StoredConfig; -import org.eclipse.jgit.lib.TextProgressMonitor; import org.eclipse.jgit.pgm.internal.CLIText; -import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.revwalk.RevWalk; -import org.eclipse.jgit.storage.file.FileRepositoryBuilder; -import org.eclipse.jgit.transport.FetchResult; -import org.eclipse.jgit.transport.RefSpec; -import org.eclipse.jgit.transport.RemoteConfig; -import org.eclipse.jgit.transport.TagOpt; -import org.eclipse.jgit.transport.Transport; import org.eclipse.jgit.transport.URIish; +import org.eclipse.jgit.util.SystemReader; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.Option; @@ -82,14 +67,15 @@ class Clone extends AbstractFetchCommand { @Option(name = "--no-checkout", aliases = { "-n" }, usage = "usage_noCheckoutAfterClone") private boolean noCheckout; + @Option(name = "--bare", usage = "usage_bareClone") + private boolean isBare; + @Argument(index = 0, required = true, metaVar = "metaVar_uriish") private String sourceUri; @Argument(index = 1, metaVar = "metaVar_directory") private String localName; - private Repository dst; - @Override protected final boolean requiresRepository() { return false; @@ -101,116 +87,42 @@ class Clone extends AbstractFetchCommand { throw die(CLIText.get().conflictingUsageOf_git_dir_andArguments); final URIish uri = new URIish(sourceUri); + File localNameF; if (localName == null) { try { localName = uri.getHumanishName(); + localNameF = new File(SystemReader.getInstance().getProperty( + Constants.OS_USER_DIR), localName); } catch (IllegalArgumentException e) { - throw die(MessageFormat.format(CLIText.get().cannotGuessLocalNameFrom, sourceUri)); + throw die(MessageFormat.format( + CLIText.get().cannotGuessLocalNameFrom, sourceUri)); } - } - if (gitdir == null) - gitdir = new File(localName, Constants.DOT_GIT).getAbsolutePath(); - - dst = new FileRepositoryBuilder().setGitDir(new File(gitdir)).build(); - dst.create(); - final StoredConfig dstcfg = dst.getConfig(); - dstcfg.setBoolean("core", null, "bare", false); //$NON-NLS-1$ //$NON-NLS-2$ - dstcfg.save(); - db = dst; - - outw.print(MessageFormat.format( - CLIText.get().initializedEmptyGitRepositoryIn, gitdir)); - outw.println(); - outw.flush(); + } else + localNameF = new File(localName); - saveRemote(uri); - final FetchResult r = runFetch(); - - if (!noCheckout) { - final Ref checkoutRef; - if (branch == null) - checkoutRef = guessHEAD(r); - else { - checkoutRef = r.getAdvertisedRef(Constants.R_HEADS + branch); - if (checkoutRef == null) - throw die(MessageFormat.format( - CLIText.get().noSuchRemoteRef, branch)); - } - doCheckout(checkoutRef); - } - } - - private void saveRemote(final URIish uri) throws URISyntaxException, - IOException { - final StoredConfig dstcfg = dst.getConfig(); - final RemoteConfig rc = new RemoteConfig(dstcfg, remoteName); - rc.addURI(uri); - rc.addFetchRefSpec(new RefSpec().setForceUpdate(true) - .setSourceDestination(Constants.R_HEADS + "*", //$NON-NLS-1$ - Constants.R_REMOTES + remoteName + "/*")); //$NON-NLS-1$ - rc.update(dstcfg); - dstcfg.save(); - } - - private FetchResult runFetch() throws URISyntaxException, IOException { - final Transport tn = Transport.open(db, remoteName); - final FetchResult r; - try { - tn.setTagOpt(TagOpt.FETCH_TAGS); - r = tn.fetch(new TextProgressMonitor(), null); - } finally { - tn.close(); - } - showFetchResult(r); - return r; - } - - private static Ref guessHEAD(final FetchResult result) { - final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD); - Ref head = null; - for (final Ref r : result.getAdvertisedRefs()) { - final String n = r.getName(); - if (!n.startsWith(Constants.R_HEADS)) - continue; - if (idHEAD == null || head != null) - continue; - if (r.getObjectId().equals(idHEAD.getObjectId())) - head = r; - } - if (idHEAD != null && head == null) - head = idHEAD; - return head; - } - - private void doCheckout(final Ref branch) throws IOException { if (branch == null) - throw die(CLIText.get().cannotChekoutNoHeadsAdvertisedByRemote); - if (!Constants.HEAD.equals(branch.getName())) { - RefUpdate u = db.updateRef(Constants.HEAD); - u.disableRefLog(); - u.link(branch.getName()); - } - - final RevCommit commit = parseCommit(branch); - final RefUpdate u = db.updateRef(Constants.HEAD); - u.setNewObjectId(commit); - u.forceUpdate(); + branch = Constants.HEAD; - DirCache dc = db.lockDirCache(); - DirCacheCheckout co = new DirCacheCheckout(db, dc, commit.getTree()); - co.checkout(); - } + CloneCommand command = Git.cloneRepository(); + command.setURI(sourceUri).setRemote(remoteName).setBare(isBare) + .setNoCheckout(noCheckout).setBranch(branch); - private RevCommit parseCommit(final Ref branch) - throws MissingObjectException, IncorrectObjectTypeException, - IOException { - final RevWalk rw = new RevWalk(db); - final RevCommit commit; + command.setGitDir(gitdir == null ? null : new File(gitdir)); + command.setDirectory(localNameF); + outw.println(MessageFormat.format(CLIText.get().cloningInto, localName)); try { - commit = rw.parseCommit(branch.getObjectId()); + db = command.call().getRepository(); + if (db.resolve(Constants.HEAD) == null) + outw.println(CLIText.get().clonedEmptyRepository); + } catch (InvalidRemoteException e) { + throw die(MessageFormat.format(CLIText.get().doesNotExist, + sourceUri)); } finally { - rw.release(); + if (db != null) + db.close(); } - return commit; + + outw.println(); + outw.flush(); } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java index 93fcd66c55..6262ad2469 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsRemote.java @@ -46,16 +46,24 @@ package org.eclipse.jgit.pgm; import java.io.IOException; +import java.util.Comparator; +import java.util.TreeSet; -import org.kohsuke.args4j.Argument; -import org.kohsuke.args4j.Option; +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.LsRemoteCommand; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Ref; -import org.eclipse.jgit.transport.FetchConnection; -import org.eclipse.jgit.transport.Transport; +import org.kohsuke.args4j.Argument; +import org.kohsuke.args4j.Option; @Command(common = true, usage = "usage_LsRemote") class LsRemote extends TextBuiltin { + @Option(name = "--heads", usage = "usage_lsRemoteHeads") + private boolean heads; + + @Option(name = "--tags", usage = "usage_lsRemoteTags", aliases = { "-t" }) + private boolean tags; + @Option(name = "--timeout", metaVar = "metaVar_service", usage = "usage_abortConnectionIfNoActivity") int timeout = -1; @@ -64,19 +72,19 @@ class LsRemote extends TextBuiltin { @Override protected void run() throws Exception { - final Transport tn = Transport.open(db, remote); - if (0 <= timeout) - tn.setTimeout(timeout); - final FetchConnection c = tn.openFetch(); - try { - for (final Ref r : c.getRefs()) { - show(r.getObjectId(), r.getName()); - if (r.getPeeledObjectId() != null) - show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$ + LsRemoteCommand command = Git.lsRemoteRepository().setRemote(remote) + .setTimeout(timeout).setHeads(heads).setTags(tags); + TreeSet<Ref> refs = new TreeSet<Ref>(new Comparator<Ref>() { + + public int compare(Ref r1, Ref r2) { + return r1.getName().compareTo(r2.getName()); } - } finally { - c.close(); - tn.close(); + }); + refs.addAll(command.call()); + for (final Ref r : refs) { + show(r.getObjectId(), r.getName()); + if (r.getPeeledObjectId() != null) + show(r.getPeeledObjectId(), r.getName() + "^{}"); //$NON-NLS-1$ } } diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java index c42e5fb59d..e7d995e6ae 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/internal/CLIText.java @@ -109,6 +109,8 @@ public class CLIText extends TranslationBundle { /***/ public String changesToBeCommitted; /***/ public String checkoutConflict; /***/ public String checkoutConflictPathLine; + /***/ public String clonedEmptyRepository; + /***/ public String cloningInto; /***/ public String commitLabel; /***/ public String conflictingUsageOf_git_dir_andArguments; /***/ public String couldNotCreateBranch; |