Skip to content

Commit

Permalink
fix: re-stage files after pulling (#411)
Browse files Browse the repository at this point in the history
* fix: re-stage files after pulling

This should fix an issue that prevented changes from being committed
when `git pull --rebase --autostash` used.

Issue #406

* chore: mark pre-commit hook as executable

* fix: detect conflicts after pull
  • Loading branch information
EndBug committed Jun 26, 2022
1 parent 9fc8e26 commit 0d52df4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Empty file modified .husky/pre-commit
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

22 changes: 19 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,17 @@ core.info(`Running in ${baseDir}`)
core.startGroup('Internal logs')
core.info('> Staging files...')

const peh = getInput('pathspec_error_handling')
const ignoreErrors =
getInput('pathspec_error_handling') == 'ignore' ? 'pathspec' : 'none'

if (getInput('add')) {
core.info('> Adding files...')
await add(peh == 'ignore' ? 'pathspec' : 'none')
await add(ignoreErrors)
} else core.info('> No files to add.')

if (getInput('remove')) {
core.info('> Removing files...')
await remove(peh == 'ignore' ? 'pathspec' : 'none')
await remove(ignoreErrors)
} else core.info('> No files to remove.')

core.info('> Checking for uncommitted changes in the git working tree...')
Expand Down Expand Up @@ -76,6 +77,21 @@ core.info(`Running in ${baseDir}`)
await git
.fetch(undefined, log)
.pull(undefined, undefined, matchGitArgs(pullOption), log)

core.info('> Checking for conflicts...')
const status = await git.status(undefined, log)

if (!status.conflicted.length) {
core.info('> No conflicts found.')
core.info('> Re-staging files...')
if (getInput('add')) await add(ignoreErrors)
if (getInput('remove')) await remove(ignoreErrors)
} else
throw new Error(
`There are ${
status.conflicted.length
} conflicting files: ${status.conflicted.join(',')}`
)
} else core.info('> Not pulling from repo.')

core.info('> Creating commit...')
Expand Down

0 comments on commit 0d52df4

Please sign in to comment.