diff --git a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java index 9a787a1cb9..d24928dc70 100644 --- a/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java +++ b/src/main/java/org/kohsuke/github/GHCreateRepositoryBuilder.java @@ -98,6 +98,18 @@ public GHCreateRepositoryBuilder gitignoreTemplate(String language) throws IOExc return with("gitignore_template", language); } + /** + * Include all branches when creating from a template repository + * + * @param includeAllBranches + * whether or not to include all branches from the template repository + * @return a builder to continue with building + * @throws IOException + */ + public GHCreateRepositoryBuilder includeAllBranches(boolean includeAllBranches) throws IOException { + return with("include_all_branches", includeAllBranches); + } + /** * Desired license template to apply. * diff --git a/src/test/java/org/kohsuke/github/GHOrganizationTest.java b/src/test/java/org/kohsuke/github/GHOrganizationTest.java index 89388427b4..cb9694bb41 100644 --- a/src/test/java/org/kohsuke/github/GHOrganizationTest.java +++ b/src/test/java/org/kohsuke/github/GHOrganizationTest.java @@ -264,6 +264,37 @@ public void testCreateRepositoryWithTemplateAndGHRepository() throws IOException } + /** + * Test create a repository from a template with all branches included + * + * @throws IOException + * Signals that an I/O exception has occurred. + * @throws InterruptedException + * Signals that Thread.sleep() was interrupted + */ + + @Test + public void testCreateRepositoryWithTemplateAndIncludeAllBranches() throws IOException, InterruptedException { + cleanupRepository(GITHUB_API_TEST_ORG + '/' + GITHUB_API_TEST); + + GHOrganization org = gitHub.getOrganization(GITHUB_API_TEST_ORG); + GHRepository templateRepository = org.getRepository(GITHUB_API_TEMPLATE_TEST); + + GHRepository repository = gitHub.createRepository(GITHUB_API_TEST) + .fromTemplateRepository(templateRepository) + .includeAllBranches(true) + .owner(GITHUB_API_TEST_ORG) + .create(); + + assertThat(repository, notNullValue()); + + // give it a moment for branches to be created + Thread.sleep(1500); + + assertThat(repository.getBranches().keySet(), equalTo(templateRepository.getBranches().keySet())); + + } + /** * Test create team. *