Uploaded image for project: 'Bitbucket Cloud'
  1. Bitbucket Cloud
  2. BCLOUD-14645

Git: Fatal Error running `git diff`

    XMLWordPrintable

Details

    Description

      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
      

      Attachments

        Activity

          People

            ayang@atlassian.com Aneita
            ce081a7efb71 jondum-raprec
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: