Skip to content

Commit

Permalink
FORGE-77
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Jan 25, 2012
1 parent d0fc315 commit 06d5296
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 255 deletions.
5 changes: 0 additions & 5 deletions dist/build.xml
Expand Up @@ -271,14 +271,9 @@
</module-def>

<module-def name="org.jboss.forge.git">
<maven-resource group="args4j" artifact="args4j" />
<maven-resource group="com.jcraft" artifact="jsch" />
<maven-resource group="org.jboss.forge" artifact="forge-git-tools" />
<maven-resource group="org.eclipse.jgit" artifact="org.eclipse.jgit" />
<maven-resource group="org.eclipse.jgit" artifact="org.eclipse.jgit.console" />
<maven-resource group="org.eclipse.jgit" artifact="org.eclipse.jgit.iplog" />
<maven-resource group="org.eclipse.jgit" artifact="org.eclipse.jgit.pgm" />
<maven-resource group="org.eclipse.jgit" artifact="org.eclipse.jgit.ui" />
</module-def>

<module-def name="org.jboss.forge.maven.api">
Expand Down
31 changes: 9 additions & 22 deletions git-tools/pom.xml
@@ -1,45 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<artifactId>forge-parent</artifactId>
<groupId>org.jboss.forge</groupId>
<version>1.0.0-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<artifactId>forge-git-tools</artifactId>

<name>Forge - Git Integration</name>
<description>Isolates Forge build from the addition of another Maven repository for Git</description>

<dependencies>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.pgm</artifactId>
<artifactId>org.eclipse.jgit</artifactId>
<version>1.2.0.201112221803-r</version>
</dependency>

<dependency>
<groupId>org.jboss.forge</groupId>
<artifactId>forge-shell-api</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<repositories>
<repository>
<id>jgit-repository</id>
<url>http://download.eclipse.org/jgit/maven</url>
<snapshots>
<enabled>false</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
</repository>
</repositories>


</project>
198 changes: 0 additions & 198 deletions git-tools/src/main/java/org/jboss/forge/git/Clone.java

This file was deleted.

53 changes: 30 additions & 23 deletions git-tools/src/main/java/org/jboss/forge/git/GitUtils.java
Expand Up @@ -22,16 +22,17 @@
package org.jboss.forge.git;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.eclipse.jgit.api.CheckoutCommand;
import org.eclipse.jgit.api.CloneCommand;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.api.FetchCommand;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.ListBranchCommand;
import org.eclipse.jgit.api.PullCommand;
import org.eclipse.jgit.api.PullResult;
import org.eclipse.jgit.api.TagCommand;
import org.eclipse.jgit.api.errors.CanceledException;
import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException;
import org.eclipse.jgit.api.errors.DetachedHeadException;
Expand All @@ -45,9 +46,9 @@
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryBuilder;
import org.eclipse.jgit.lib.TextProgressMonitor;
import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.transport.FetchResult;
import org.eclipse.jgit.transport.RefSpec;
import org.jboss.forge.resources.DirectoryResource;
Expand All @@ -62,8 +63,10 @@ public abstract class GitUtils
{
public static Git clone(final DirectoryResource dir, final String repoUri) throws IOException
{
new Clone().run(dir.getUnderlyingResourceObject(), repoUri);
return git(dir);
CloneCommand clone = Git.cloneRepository().setURI(repoUri)
.setDirectory(dir.getUnderlyingResourceObject());
Git git = clone.call();
return git;
}

public static Git git(final DirectoryResource dir) throws IOException
Expand All @@ -85,13 +88,13 @@ public static Ref checkout(final Git git, final String remote, final boolean cre
return checkout.call();
}

public static Ref checkout(final Git git, final Ref remote, final boolean createBranch,
public static Ref checkout(final Git git, final Ref localRef, final boolean createBranch,
final SetupUpstreamMode mode, final boolean force)
throws JGitInternalException,
RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException
{
CheckoutCommand checkout = git.checkout();
checkout.setName(remote.getName());
checkout.setName(Repository.shortenRefName(localRef.getName()));
checkout.setForce(force);
checkout.setUpstreamMode(mode);
return checkout.call();
Expand Down Expand Up @@ -135,7 +138,8 @@ public static Git init(final DirectoryResource dir) throws IllegalArgumentExcept
}

public static PullResult pull(final Git git, final int timeout) throws WrongRepositoryStateException,
InvalidConfigurationException, DetachedHeadException, InvalidRemoteException, CanceledException
InvalidConfigurationException, DetachedHeadException, InvalidRemoteException, CanceledException,
RefNotFoundException, NoHeadException
{
PullCommand pull = git.pull();
if (timeout >= 0)
Expand All @@ -146,22 +150,25 @@ public static PullResult pull(final Git git, final int timeout) throws WrongRepo
return result;
}

public static List<Ref> getBranches(final Git repo) throws JGitInternalException, ConcurrentRefUpdateException,
public static List<Ref> getRemoteBranches(final Git repo) throws JGitInternalException,
ConcurrentRefUpdateException,
InvalidTagNameException, NoHeadException
{
ListBranchCommand branchListCommand = repo.branchList();
List<Ref> branchList = branchListCommand.call();

return branchList;
}

public static List<Ref> getTags(final Git repo) throws JGitInternalException, ConcurrentRefUpdateException,
InvalidTagNameException, NoHeadException
{
TagCommand tagCommand = repo.tag();
RevTag revTag = tagCommand.call();
String tagName = revTag.getTagName();

return null;
List<Ref> results = new ArrayList<Ref>();
try {
FetchResult fetch = repo.fetch().setRemote("origin").call();
Collection<Ref> refs = fetch.getAdvertisedRefs();
for (Ref ref : refs) {
if (ref.getName().startsWith("refs/heads"))
{
results.add(ref);
}
}
}
catch (InvalidRemoteException e) {
e.printStackTrace();
}

return results;
}
}

0 comments on commit 06d5296

Please sign in to comment.