■ ■ ■ ■ ■ ■
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, new LineConsumer() { |
| 634 | + | |
| 635 | + | @Override |
| 636 | + | public void consume(String line) { |
| 637 | + | if (line.startsWith("Filtering content:")) |
| 638 | + | infoLogger.consume(line); |
| 639 | + | else |
| 640 | + | errorLogger.consume(line); |
| 641 | + | } |
| 642 | + | |
| 643 | + | }).checkReturnCode(); |
| 644 | + | |
| 645 | + | if (withSubmodules && new File(git.workingDir(), ".gitmodules").exists()) { |
629 | 646 | | // deinit submodules in case submodule url is changed |
630 | 647 | | git.clearArgs(); |
631 | 648 | | git.addArgs("submodule", "deinit", "--all", "--force", "--quiet"); |
| skipped 42 lines |
674 | 691 | | return SerializationUtils.deserialize(jobDataBytes); |
675 | 692 | | } |
676 | 693 | | |
| 694 | + | public static void testGitLfsAvailability(Commandline git, TaskLogger jobLogger) { |
| 695 | + | File userHome = FileUtils.createTempDir("user"); |
| 696 | + | try { |
| 697 | + | jobLogger.log("Checking if git-lfs exists..."); |
| 698 | + | git.clearArgs(); |
| 699 | + | git.environments().put("HOME", userHome.getAbsolutePath()); |
| 700 | + | if (SystemUtils.IS_OS_MAC_OSX) { |
| 701 | + | String path = System.getenv("PATH") + ":/usr/local/bin"; |
| 702 | + | git.environments().put("PATH", path); |
| 703 | + | } |
| 704 | + | |
| 705 | + | git.addArgs("lfs", "version"); |
| 706 | + | |
| 707 | + | AtomicBoolean lfsExists = new AtomicBoolean(true); |
| 708 | + | ExecutionResult result = git.execute(new LineConsumer() { |
| 709 | + | |
| 710 | + | @Override |
| 711 | + | public void consume(String line) { |
| 712 | + | } |
| 713 | + | |
| 714 | + | }, new LineConsumer() { |
| 715 | + | |
| 716 | + | @Override |
| 717 | + | public void consume(String line) { |
| 718 | + | if (line.startsWith("git: 'lfs' is not a git command")) |
| 719 | + | lfsExists.set(false); |
| 720 | + | if (lfsExists.get()) |
| 721 | + | jobLogger.error(line); |
| 722 | + | } |
| 723 | + | |
| 724 | + | }); |
| 725 | + | if (lfsExists.get()) { |
| 726 | + | result.checkReturnCode(); |
| 727 | + | jobLogger.log("git-lfs found"); |
| 728 | + | } else { |
| 729 | + | jobLogger.warning("WARNING: Executable 'git-lfs' not found. You will not be able to retrieve LFS files"); |
| 730 | + | } |
| 731 | + | } finally { |
| 732 | + | FileUtils.deleteDir(userHome, 3); |
| 733 | + | } |
| 734 | + | } |
| 735 | + | |
677 | 736 | | public static void sidecar(String serverUrl, String jobToken, boolean test) { |
678 | 737 | | LeafHandler commandHandler = new LeafHandler() { |
679 | 738 | | |
| skipped 139 lines |
819 | 878 | | } |
820 | 879 | | |
821 | 880 | | public static void checkoutCode(String serverUrl, String jobToken, String positionStr, |
822 | | - | int cloneDepth, CloneInfo cloneInfo) throws IOException { |
| 881 | + | boolean withLfs, boolean withSubmodules, int cloneDepth, CloneInfo cloneInfo) throws IOException { |
823 | 882 | | JobData jobData = readJobData(); |
824 | 883 | | |
825 | 884 | | logger.info("Checking out code from {}...", cloneInfo.getCloneUrl()); |
| skipped 33 lines |
859 | 918 | | } |
860 | 919 | | |
861 | 920 | | cloneRepository(git, cloneInfo.getCloneUrl(), cloneInfo.getCloneUrl(), |
862 | | - | jobData.getCommitHash(), cloneDepth, infoLogger, errorLogger); |
| 921 | + | jobData.getCommitHash(), withLfs, withSubmodules, cloneDepth, |
| 922 | + | infoLogger, errorLogger); |
863 | 923 | | } |
864 | 924 | | |
865 | 925 | | public static void runServerStep(String serverUrl, String jobToken, String positionStr, |
| skipped 172 lines |