Git: Fatal Error running `git diff`

XMLWordPrintable

      I am building a CI solution for Salesforce code. In Salesforce, there are no atomic deploys, so you must manually delete files that have been renamed or removed. Yea.

      My solution to this was to track the commit the pipeline runs on so that I can generate a list of all deleted files from the previous pipeline run with git diff <previous sha>..<current sha>.

      The problem is that even with clone: depth: full enabled in the pipeline.yml, git throws an error because the previous commit doesn't seem to exist. I verified this is an issue by recreating the pipeline in a Docker container. When I use my normally cloned repo on my local machine, the git diff command works fine. When I clone the repo the way the pipeline does via git clone --branch="staging" <url>, then the command fails and returns a fatal: bad object <sha> error.

      My pipeline:

      image: node:latest
      
      clone:
        depth: full
      
      definitions:
        caches:
          sfdx: ~/.sfdx
          sfdx-libs: ~/.local/share/sfdx
          yarn: ~/.yarn
      pipelines:
      
        branches:
          staging:
              - step:
                  caches:
                    - node
                    - sfdx
                    - sfdx-libs
                  script:
                    - git show $BITBUCKET_COMMIT
                    - echo $BITBUCKET_COMMIT > ~/.sfdx/current-build
                    - tasks/build $BITBUCKET_BRANCH
                    - tasks/deploy $BITBUCKET_BRANCH
                    - echo $BITBUCKET_COMMIT > ~/.sfdx/previous-build
      

            Assignee:
            Aneita
            Reporter:
            jondum-raprec
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: