mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 23:15:43 +01:00
Filter master branch correctly on initial mirror (#1747)
On the first synchronization, the clone has the implicit branch "master". This cannot be changed in JGit. When we fetch the refs from the repository that should be mirrored, the master branch of the clone will be updated to the revision of the remote repository (if it has a master branch). If now the master branch shall be filtered from mirroring (ie. if it is rejected), we normally would delete the ref in this clone. But because it is the current branch, it cannot be deleted. We detect this and later, after we have pushed the result, delete the master branch by pushing an empty ref to the central repository.
This commit is contained in:
@@ -112,6 +112,36 @@ public class GitMirrorCommandTest extends AbstractGitCommandTestBase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFilterMasterBranchWhenFilteredOnInitialMirror() throws IOException, GitAPIException {
|
||||
MirrorCommandResult result = callMirrorCommand(repositoryDirectory.getAbsolutePath(), c -> {
|
||||
c.setFilter(new MirrorFilter() {
|
||||
@Override
|
||||
public Filter getFilter(FilterContext context) {
|
||||
return new Filter() {
|
||||
@Override
|
||||
public Result acceptBranch(BranchUpdate branch) {
|
||||
if (branch.getBranchName().equals("master")) {
|
||||
return Result.reject("master not accepted");
|
||||
} else {
|
||||
return Result.accept();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
assertThat(result.getResult()).isEqualTo(REJECTED_UPDATES);
|
||||
assertThat(result.getLog())
|
||||
.contains("- 000000000..fcd0ef183 master (master not accepted)");
|
||||
|
||||
try (Git createdMirror = Git.open(clone)) {
|
||||
assertThat(createdMirror.branchList().call().stream().filter(r -> r.getName().contains("master")).findAny())
|
||||
.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateEmptyLogWhenNoChangesFound() {
|
||||
callMirrorCommand();
|
||||
|
||||
Reference in New Issue
Block a user