Skip to content

Commit a6792cf

Browse files
committed
Merge branch 'master' into release/4
# Conflicts: # version
2 parents 0a23073 + e3f2794 commit a6792cf

File tree

5 files changed

+49
-19
lines changed

5 files changed

+49
-19
lines changed

build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ jacocoTestReport {
2121
}
2222
}
2323

24+
test {
25+
testLogging {
26+
events "failed"
27+
exceptionFormat "full"
28+
}
29+
}
30+
2431
repositories {
2532
mavenCentral()
2633
}

src/main/java/org/scm4j/vcs/api/workingcopy/IVCSRepositoryWorkspace.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
public interface IVCSRepositoryWorkspace {
77

88
IVCSLockedWorkingCopy getVCSLockedWorkingCopy() throws IOException;
9+
10+
IVCSLockedWorkingCopy getVCSLockedWorkingCopyTemp() throws IOException;
911

1012
File getRepoFolder();
1113

src/main/java/org/scm4j/vcs/api/workingcopy/VCSLockedWorkingCopy.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,31 @@ public void setCorrupted(Boolean isCorrupt) {
4040
this.corrupt = isCorrupt;
4141
}
4242

43-
protected VCSLockedWorkingCopy (IVCSRepositoryWorkspace vcsRepo) throws IOException {
43+
protected VCSLockedWorkingCopy (IVCSRepositoryWorkspace vcsRepo, boolean isTemp) throws IOException {
4444
this.vcsRepo = vcsRepo;
45-
init();
45+
this.corrupt = isTemp;
46+
init(isTemp);
4647
}
4748

4849
@Override
4950
public Boolean getCorrupted() {
5051
return corrupt;
5152
}
5253

53-
private void init() throws IOException {
54+
private void init(boolean force) throws IOException {
5455
File[] files = vcsRepo.getRepoFolder().listFiles();
55-
for (File file : files != null ? files : new File[0]) {
56-
if (file.isDirectory()) {
57-
lockFile = new File( vcsRepo.getRepoFolder(), LOCK_FILE_PREFIX + file.getName());
58-
if (!lockFile.exists()) {
59-
continue;
60-
}
61-
if (tryLockFile(lockFile)) {
62-
folder = file;
63-
state = VCSLockedWorkingCopyState.LOCKED;
64-
return;
56+
if (!force) {
57+
for (File file : files != null ? files : new File[0]) {
58+
if (file.isDirectory()) {
59+
lockFile = new File( vcsRepo.getRepoFolder(), LOCK_FILE_PREFIX + file.getName());
60+
if (!lockFile.exists()) {
61+
continue;
62+
}
63+
if (tryLockFile(lockFile)) {
64+
folder = file;
65+
state = VCSLockedWorkingCopyState.LOCKED;
66+
return;
67+
}
6568
}
6669
}
6770
}

src/main/java/org/scm4j/vcs/api/workingcopy/VCSRepositoryWorkspace.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public IVCSWorkspace getWorkspace() {
2222

2323
@Override
2424
public IVCSLockedWorkingCopy getVCSLockedWorkingCopy() throws IOException {
25-
return new VCSLockedWorkingCopy(this);
25+
return new VCSLockedWorkingCopy(this, false);
2626
}
2727

2828
private String getRepoFolderName() {
@@ -52,4 +52,9 @@ public String toString() {
5252
+ "]";
5353
}
5454

55+
@Override
56+
public IVCSLockedWorkingCopy getVCSLockedWorkingCopyTemp() throws IOException {
57+
return new VCSLockedWorkingCopy(this, true);
58+
}
59+
5560
}

src/test/java/org/scm4j/vcs/api/workingcopy/VCSLockedWorkingCopyTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import org.junit.Before;
44
import org.junit.Test;
55

6+
import java.io.File;
67
import java.io.FileInputStream;
78
import java.nio.channels.FileChannel;
89
import java.nio.channels.NonWritableChannelException;
@@ -53,22 +54,22 @@ public void testLockingFewWorkspaces() throws Exception {
5354

5455
@Test
5556
public void testReusingUnlockedWorkspaces() throws Exception {
56-
VCSLockedWorkingCopy w1 = new VCSLockedWorkingCopy(r);
57+
VCSLockedWorkingCopy w1 = new VCSLockedWorkingCopy(r, false);
5758
w1.close();
58-
VCSLockedWorkingCopy w2 = new VCSLockedWorkingCopy(r);
59+
VCSLockedWorkingCopy w2 = new VCSLockedWorkingCopy(r, false);
5960
assertEquals(w1.getFolder().getName(), w2.getFolder().getName());
6061
w2.close();
6162

6263
// if lock file does not exists then a new WC should be created
6364
w1.getLockFile().delete();
64-
w2 = new VCSLockedWorkingCopy(r);
65+
w2 = new VCSLockedWorkingCopy(r, false);
6566
assertNotEquals(w1.getFolder().getName(), w2.getFolder().getName());
6667
w2.close();
6768
}
6869

6970
@Test
7071
public void testCorruptingWorkspace() throws Exception {
71-
VCSLockedWorkingCopy workspace = new VCSLockedWorkingCopy(r);
72+
VCSLockedWorkingCopy workspace = new VCSLockedWorkingCopy(r, false);
7273
workspace.setCorrupted(true);
7374
workspace.close();
7475
assertFalse(workspace.getFolder().exists());
@@ -77,8 +78,20 @@ public void testCorruptingWorkspace() throws Exception {
7778

7879
@Test
7980
public void testToString() throws Exception {
80-
try (VCSLockedWorkingCopy lwc = new VCSLockedWorkingCopy(r)) {
81+
try (VCSLockedWorkingCopy lwc = new VCSLockedWorkingCopy(r, false)) {
8182
assertTrue(lwc.toString().contains(r.getRepoFolder().getPath()));
8283
}
8384
}
85+
86+
@Test
87+
public void testTempLWCObtain() throws Exception {
88+
File lwcFolder;
89+
try (IVCSLockedWorkingCopy lwc = r.getVCSLockedWorkingCopy()) {
90+
lwcFolder = lwc.getFolder();
91+
}
92+
try (IVCSLockedWorkingCopy tempLWC = r.getVCSLockedWorkingCopyTemp()) {
93+
assertFalse(lwcFolder.getName().equals(tempLWC.getFolder().getName()));
94+
assertTrue(tempLWC.getCorrupted());
95+
}
96+
}
8497
}

0 commit comments

Comments
 (0)