Skip to content

Commit abb6753

Browse files
committedMay 24, 2015
Fix some issues with repo creation
1 parent 182db45 commit abb6753

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed
 

‎build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ plugins {
1212
}
1313

1414
group = 'net.minecrell'
15-
version = '0.5-SNAPSHOT'
15+
version = '0.4.1'
1616
description = 'A Gradle plugin to manage patches for Git repositories'
1717

1818
sourceCompatibility = 1.6

‎src/main/groovy/net/minecrell/gitpatcher/task/patch/ApplyPatchesTask.groovy

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ import static org.eclipse.jgit.submodule.SubmoduleWalk.getSubmoduleRepository
3030

3131
import net.minecrell.gitpatcher.git.MailPatch
3232
import org.eclipse.jgit.api.Git
33+
import org.eclipse.jgit.api.errors.InvalidRemoteException
34+
import org.eclipse.jgit.transport.RemoteConfig
35+
import org.eclipse.jgit.transport.URIish
3336
import org.gradle.api.tasks.InputFiles
3437
import org.gradle.api.tasks.OutputDirectory
3538
import org.gradle.api.tasks.OutputFile
@@ -65,12 +68,15 @@ class ApplyPatchesTask extends PatchTask {
6568
.call()
6669
}
6770

71+
def gitDir = new File(repo, '.git')
6872
Git git
69-
if (repo.isDirectory()) {
73+
if (gitDir.isDirectory() && gitDir.list().length > 0) {
7074
git = Git.open(repo)
7175
} else {
7276
logger.lifecycle 'Creating {} repository...', repo
7377

78+
assert repo.deleteDir()
79+
7480
git = Git.cloneRepository()
7581
.setURI(source.toURI().toString())
7682
.setDirectory(repo)
@@ -80,7 +86,21 @@ class ApplyPatchesTask extends PatchTask {
8086
withGit(git) {
8187
logger.lifecycle 'Resetting {}...', repo
8288

83-
fetch().setRemote('origin').call()
89+
try {
90+
fetch().setRemote('origin').call()
91+
} catch (InvalidRemoteException e) {
92+
// Reset remote (maybe it was changed or something)
93+
def config = new RemoteConfig(repository.getConfig(), 'origin')
94+
for (URIish uri : config.getURIs().toArray()) {
95+
config.removeURI(uri)
96+
}
97+
config.addURI(new URIish(source.toURI().toString()))
98+
config.update(repository.getConfig())
99+
100+
// Fetch again
101+
fetch().setRemote('origin').call()
102+
}
103+
84104

85105
if (repository.getRef('master') == null) {
86106
// Create the master branch

0 commit comments

Comments
 (0)