dotCMS / dotCMS/core

git diff Step Fails with “fatal: bad object” Error in GitHub Action

Open
#31,432 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

dotCMS : CLI Team : Scout Type : Defect
Dominant language
Java
Stars
970
Forks
486
Avg merge
3d 33m
Merged PRs (30d)
170

Description

Parent Issue

https://github.com/dotCMS/core/issues/26300

Problem Statement

One of the steps in our main.yaml workflow runs a git diff operation to compare GitHub events before and after a change. The output of this git diff command is written to a changed-files.txt file, which is then used in a subsequent step to report modified files.

The file is tools/dotcms-cli/action/.github/workflows/main.yml

The Code that needs the fix looks like this:

      - name: Get changes
        run: |
          git diff --name-only ${{ github.event.before }} ${{ github.event.after }} > changed_files.txt

      - name: List changed files
        run: |
          while IFS= read -r line
          do
            echo ""$line" was changed"
          done < changed_files.txt

These two steps are used to list the files that have changed between events.

the proposed fix looks as follows:

- name: Get changes
        run: |
          git diff --name-only ${{ github.event.before }} ${{ github.event.after }} > changed_files.txt 2>/dev/null || echo -n "" > changed_files.txt

      - name: List changed files
        run: |
          while IFS= read -r line
          do
            echo ""$line" was changed"
          done < changed_files.txt

Steps to Reproduce

it isn't clear how this can happen
However

  • I created an empty repo on GitHub
  • I cloned the repo locally
  • Checked out the demo and the git pushed
  • then pushed the changes with the required workflows
  • and finally added a .env file
  • Then when I felt the GHA was ready I added an image under
    files/working/en-us/demo.dotcms.com/images/
    and git pushed to the remote repo

Then the error came up

Acceptance Criteria
•	The git diff step should always find valid commit references.
•	If an issue occurs, the step should recover gracefully and proceed without breaking the workflow.
dotCMS Version

current main

Proposed Objective

Technical User Experience

Proposed Priority

Please Select

External Links... Slack Conversations, Support Tickets, Figma Designs, etc.

No response

Assumptions & Initiation Needs

No response

Quality Assurance Notes & Workarounds

No response

Sub-Tasks & Estimates

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read tools/dotcms-cli/action/.github/workflows/main.yml and inspect the “Get changes” and “List changed files” steps. Run the workflow or reproduce the git diff failure if possible, then verify that invalid references do not break the workflow and that changed_files.txt remains safe to consume.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, github-actions, shell
Domain
ci-cd
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.