Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-65319

Relative paths to git reference repo for submodules throws exception

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Won't Fix
    • Component/s: git-client-plugin
    • Labels:
      None
    • Environment:
      Jenkins 2.286, Git plugin 4.7.1, Git client plugin 3.7.1
    • Similar Issues:

      Description

      Steps to reproduce:

      • Set up a reference repository in the build node's remote root directory under refrepo/my_repo.git
      • Configure a new job to use this reference repo both during clone and submodule update:
      • Start a build. Gives the following output:
         
        The recommended git tool is: NONE
        using credential ****
        Cloning the remote Git repository
        Cloning repository ssh://git@****/my_repo.git
         > git init /home/**** # timeout=10
        Using reference repository: refrepo/my_repo.git
        Fetching upstream changes from ssh://git@****/my_repo.git
         > git --version # timeout=10
         > git --version # 'git version 2.7.4'
        using GIT_SSH to set credentials SSH Key for accessing ****
         > git fetch --tags --progress ssh://git@****/my_repo.git +refs/heads/*:refs/remotes/origin/* # timeout=10
        Avoid second fetch
        Checking out Revision **** (main)
        Commit message: "****"
         > git config remote.origin.url ssh://git@****/my_repo.git # timeout=10
         > git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/* # timeout=10
         > git config core.sparsecheckout # timeout=10
         > git checkout -f **** # timeout=10
         > git rev-list --no-walk **** # timeout=10
        hudson.plugins.git.GitException: Command "git submodule update --reference refrepo/my_repo.git modules/my_submodule" returned status code 128:
        stdout: 
        stderr: Cloning into 'modules/my_submodule'...
        fatal: Could not switch to 'refrepo/': No such file or directory
        fatal: clone of 'ssh://git@****/my_submodule.git' into submodule path 'modules/my_submodule' failed
        

      I'm not sure if relative paths to reference repositories are supposed to work/supported in the Git client plugin, but I find this inconsistency between clone and submodule update odd.

        Attachments

          Activity

          Hide
          markewaite Mark Waite added a comment -

          Thanks for the report. I wasn't aware of that difference.

          Unfortunately, the behavioral difference is between command line git for the main repository and command line git for submodules. This is not a behavioral difference that the git client plugin can reasonably change.

          I suspect the behavioral difference is because command line git performs a chdir before it performs operations in the submodule directory. The chdir changes the working directory of the submodule process and that breaks the relative path reference.

          Show
          markewaite Mark Waite added a comment - Thanks for the report. I wasn't aware of that difference. Unfortunately, the behavioral difference is between command line git for the main repository and command line git for submodules. This is not a behavioral difference that the git client plugin can reasonably change. I suspect the behavioral difference is because command line git performs a chdir before it performs operations in the submodule directory. The chdir changes the working directory of the submodule process and that breaks the relative path reference.
          Hide
          sixten Sixten added a comment -

          The plugin actually converts paths for the main repo to absolute paths explicitly before writing them to .git/objects/info/alternates, so I think it would make sense to do that when passing --reference to Git as well.
          What do you think about this change?

          diff --git a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
          --- a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
          +++ b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
          @@ -1411,7 +1411,7 @@ public class CliGitAPIImpl extends LegacyCompatibleGitAPIImpl {
                               else if (!referencePath.isDirectory())
                                   listener.getLogger().println("[WARNING] Reference path is not a directory: " + ref);
                               else
          -                        args.add("--reference", ref);
          +                        args.add("--reference", referencePath.getAbsolutePath());
                           }
                           if (shallow) {
                               if (depth == null) {
          
          Show
          sixten Sixten added a comment - The plugin actually converts paths for the main repo to absolute paths explicitly before writing them to .git/objects/info/alternates, so I think it would make sense to do that when passing --reference to Git as well. What do you think about this change? diff --git a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java --- a/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java +++ b/src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java @@ -1411,7 +1411,7 @@ public class CliGitAPIImpl extends LegacyCompatibleGitAPIImpl { else if (!referencePath.isDirectory()) listener.getLogger().println("[WARNING] Reference path is not a directory: " + ref); else - args.add("--reference", ref); + args.add("--reference", referencePath.getAbsolutePath()); } if (shallow) { if (depth == null) {
          Hide
          markewaite Mark Waite added a comment -

          No objections from me. That seems like a good change to make the submodule reference repo implementation consistent with the main repo implementation.

          Show
          markewaite Mark Waite added a comment - No objections from me. That seems like a good change to make the submodule reference repo implementation consistent with the main repo implementation.

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            sixten Sixten
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: