■ ■ ■ ■ ■ ■
src/main/java/io/onedev/k8shelper/KubernetesHelper.java
| skipped 496 lines |
497 | 497 | | if (executable instanceof CheckoutExecutable) { |
498 | 498 | | CheckoutExecutable checkoutExecutable = (CheckoutExecutable) executable; |
499 | 499 | | checkoutExecutable.getCloneInfo(); |
500 | | - | command = String.format("java -classpath \"%s\" io.onedev.k8shelper.CheckoutCode %s %d %s", |
501 | | - | classPath, positionStr, checkoutExecutable.getCloneDepth(), |
502 | | - | checkoutExecutable.getCloneInfo().toString()); |
| 500 | + | command = String.format("java -classpath \"%s\" io.onedev.k8shelper.CheckoutCode %s %b %b %d %s", |
| 501 | + | classPath, positionStr, checkoutExecutable.isWithLfs(), checkoutExecutable.isWithSubmodules(), |
| 502 | + | checkoutExecutable.getCloneDepth(), checkoutExecutable.getCloneInfo().toString()); |
503 | 503 | | } else { |
504 | 504 | | ServerExecutable serverExecutable = (ServerExecutable) executable; |
505 | 505 | | |
| skipped 62 lines |
568 | 568 | | } |
569 | 569 | | } |
570 | 570 | | |
571 | | - | public static void checkoutRepository(Commandline git, String commitHash, |
572 | | - | LineConsumer infoLogger, LineConsumer errorLogger) { |
573 | | - | git.clearArgs(); |
574 | | - | git.addArgs("checkout", "--quiet", commitHash); |
575 | | - | git.execute(infoLogger, errorLogger).checkReturnCode(); |
576 | | - | } |
577 | | - | |
578 | 571 | | public static void cloneRepository(Commandline git, String cloneUrl, String remoteUrl, |
579 | | - | String commitHash, int cloneDepth, LineConsumer infoLogger, LineConsumer errorLogger) { |
| 572 | + | String commitHash, boolean withLfs, boolean withSubmodules, int cloneDepth, |
| 573 | + | LineConsumer infoLogger, LineConsumer errorLogger) { |
580 | 574 | | git.clearArgs(); |
581 | 575 | | if (!new File(git.workingDir(), ".git").exists()) { |
582 | 576 | | git.addArgs("init", "."); |
| skipped 23 lines |
606 | 600 | | git.addArgs(commitHash); |
607 | 601 | | git.execute(infoLogger, errorLogger).checkReturnCode(); |
608 | 602 | | |
609 | | - | checkoutRepository(git, commitHash, infoLogger, errorLogger); |
610 | | - | |
611 | 603 | | AtomicBoolean originExists = new AtomicBoolean(false); |
612 | 604 | | git.clearArgs(); |
613 | 605 | | git.addArgs("remote", "add", "origin", remoteUrl); |
| skipped 11 lines |
625 | 617 | | if (!originExists.get()) |
626 | 618 | | result.checkReturnCode(); |
627 | 619 | | |
628 | | - | if (new File(git.workingDir(), ".gitmodules").exists()) { |
| 620 | + | if (withLfs) { |
| 621 | + | if (SystemUtils.IS_OS_MAC_OSX) { |
| 622 | + | String path = System.getenv("PATH") + ":/usr/local/bin"; |
| 623 | + | git.environments().put("PATH", path); |
| 624 | + | } |
| 625 | + | |
| 626 | + | git.clearArgs(); |
| 627 | + | git.addArgs("lfs", "install"); |
| 628 | + | git.execute(infoLogger, errorLogger).checkReturnCode(); |
| 629 | + | } |
| 630 | + | |
| 631 | + | git.clearArgs(); |
| 632 | + | git.addArgs("checkout", "--quiet", commitHash); |
| 633 | + | git.execute(infoLogger, errorLogger).checkReturnCode(); |
| 634 | + | |
| 635 | + | if (withSubmodules && new File(git.workingDir(), ".gitmodules").exists()) { |
629 | 636 | | // deinit submodules in case submodule url is changed |
630 | 637 | | git.clearArgs(); |
631 | 638 | | git.addArgs("submodule", "deinit", "--all", "--force", "--quiet"); |
| skipped 42 lines |
674 | 681 | | return SerializationUtils.deserialize(jobDataBytes); |
675 | 682 | | } |
676 | 683 | | |
| 684 | + | public static void testGitLfsAvailability(Commandline git, TaskLogger jobLogger) { |
| 685 | + | File userHome = FileUtils.createTempDir("user"); |
| 686 | + | try { |
| 687 | + | jobLogger.log("Checking if git-lfs exists..."); |
| 688 | + | git.clearArgs(); |
| 689 | + | git.environments().put("HOME", userHome.getAbsolutePath()); |
| 690 | + | if (SystemUtils.IS_OS_MAC_OSX) { |
| 691 | + | String path = System.getenv("PATH") + ":/usr/local/bin"; |
| 692 | + | git.environments().put("PATH", path); |
| 693 | + | } |
| 694 | + | |
| 695 | + | git.addArgs("lfs", "version"); |
| 696 | + | |
| 697 | + | AtomicBoolean lfsExists = new AtomicBoolean(true); |
| 698 | + | ExecutionResult result = git.execute(new LineConsumer() { |
| 699 | + | |
| 700 | + | @Override |
| 701 | + | public void consume(String line) { |
| 702 | + | } |
| 703 | + | |
| 704 | + | }, new LineConsumer() { |
| 705 | + | |
| 706 | + | @Override |
| 707 | + | public void consume(String line) { |
| 708 | + | if (line.startsWith("git: 'lfs' is not a git command")) |
| 709 | + | lfsExists.set(false); |
| 710 | + | if (lfsExists.get()) |
| 711 | + | jobLogger.error(line); |
| 712 | + | } |
| 713 | + | |
| 714 | + | }); |
| 715 | + | if (lfsExists.get()) { |
| 716 | + | result.checkReturnCode(); |
| 717 | + | jobLogger.log("git-lfs found"); |
| 718 | + | } else { |
| 719 | + | jobLogger.warning("WARNING: Executable 'git-lfs' not found. You will not be able to retrieve LFS files"); |
| 720 | + | } |
| 721 | + | } finally { |
| 722 | + | FileUtils.deleteDir(userHome, 3); |
| 723 | + | } |
| 724 | + | } |
| 725 | + | |
677 | 726 | | public static void sidecar(String serverUrl, String jobToken, boolean test) { |
678 | 727 | | LeafHandler commandHandler = new LeafHandler() { |
679 | 728 | | |
| skipped 139 lines |
819 | 868 | | } |
820 | 869 | | |
821 | 870 | | public static void checkoutCode(String serverUrl, String jobToken, String positionStr, |
822 | | - | int cloneDepth, CloneInfo cloneInfo) throws IOException { |
| 871 | + | boolean withLfs, boolean withSubmodules, int cloneDepth, CloneInfo cloneInfo) throws IOException { |
823 | 872 | | JobData jobData = readJobData(); |
824 | 873 | | |
825 | 874 | | logger.info("Checking out code from {}...", cloneInfo.getCloneUrl()); |
| skipped 33 lines |
859 | 908 | | } |
860 | 909 | | |
861 | 910 | | cloneRepository(git, cloneInfo.getCloneUrl(), cloneInfo.getCloneUrl(), |
862 | | - | jobData.getCommitHash(), cloneDepth, infoLogger, errorLogger); |
| 911 | + | jobData.getCommitHash(), withLfs, withSubmodules, cloneDepth, |
| 912 | + | infoLogger, errorLogger); |
863 | 913 | | } |
864 | 914 | | |
865 | 915 | | public static void runServerStep(String serverUrl, String jobToken, String positionStr, |
| skipped 172 lines |