has-changed-path icon indicating copy to clipboard operation
has-changed-path copied to clipboard

Does this handle pushing multiple commits at once? If so, how?

Open bertrand-caron opened this issue 2 years ago • 3 comments

Hi,

Thank you for this awesome project.

Does this support pushing multiple commits at once? This code suggest it does not:

  const exitCode = await exec.exec('git', [
    'diff',
    '--quiet',
    'HEAD~1',
    'HEAD',
    '--',
    ...paths,
  ], {
    ignoreReturnCode: true,
    silent: false,
    cwd: getCWD()
  })

Any plans to add support for this feature?

bertrand-caron avatar Feb 03 '22 01:02 bertrand-caron

(I guess the next question would be: how to know which git ref to use, i.e. when was the last push to that branch?)

bertrand-caron avatar Feb 03 '22 01:02 bertrand-caron

The approach I can think of for this would be to use:

on:
  pull_request:
    types:
      - closed

and then run the job conditionally on if: github.event.pull_request.merged == true which gives you access to github.event.pull_request.commits which would be great if we could then do:

      - uses: marceloprado/has-changed-path@v1
        id: changed-service
        with:
          commit_count: github.event.pull_request.commits
          paths: thepath

and the code above would be updated to:

  const exitCode = await exec.exec('git', [
    'diff',
    '--quiet',
    'HEAD~${commit_count}',
    'HEAD',
    '--',
    ...paths,
  ], {
    ignoreReturnCode: true,
    silent: false,
    cwd: getCWD()
  })

and default the value to 1.

ziazon avatar Mar 24 '22 18:03 ziazon

I decided to just roll my own check command instead which looks like this:

      - name: Check for Changes
        id: changes
        run: |
          echo ::set-output name=HAS_CHANGES::$(git diff --quiet HEAD~${{ github.event.pull_request.commits }} HEAD -- path/here || echo $?)

then later just do

if: steps.changes.outputs.HAS_CHANGES == '1'

ziazon avatar Mar 24 '22 19:03 ziazon