Skip to content

Commit 0d52df4

Browse files
authored
fix: re-stage files after pulling (#411)
* 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
1 parent 9fc8e26 commit 0d52df4

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

.husky/pre-commit

100644100755
File mode changed.

lib/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,17 @@ core.info(`Running in ${baseDir}`)
1616
core.startGroup('Internal logs')
1717
core.info('> Staging files...')
1818

19-
const peh = getInput('pathspec_error_handling')
19+
const ignoreErrors =
20+
getInput('pathspec_error_handling') == 'ignore' ? 'pathspec' : 'none'
2021

2122
if (getInput('add')) {
2223
core.info('> Adding files...')
23-
await add(peh == 'ignore' ? 'pathspec' : 'none')
24+
await add(ignoreErrors)
2425
} else core.info('> No files to add.')
2526

2627
if (getInput('remove')) {
2728
core.info('> Removing files...')
28-
await remove(peh == 'ignore' ? 'pathspec' : 'none')
29+
await remove(ignoreErrors)
2930
} else core.info('> No files to remove.')
3031

3132
core.info('> Checking for uncommitted changes in the git working tree...')
@@ -76,6 +77,21 @@ core.info(`Running in ${baseDir}`)
7677
await git
7778
.fetch(undefined, log)
7879
.pull(undefined, undefined, matchGitArgs(pullOption), log)
80+
81+
core.info('> Checking for conflicts...')
82+
const status = await git.status(undefined, log)
83+
84+
if (!status.conflicted.length) {
85+
core.info('> No conflicts found.')
86+
core.info('> Re-staging files...')
87+
if (getInput('add')) await add(ignoreErrors)
88+
if (getInput('remove')) await remove(ignoreErrors)
89+
} else
90+
throw new Error(
91+
`There are ${
92+
status.conflicted.length
93+
} conflicting files: ${status.conflicted.join(',')}`
94+
)
7995
} else core.info('> Not pulling from repo.')
8096

8197
core.info('> Creating commit...')

0 commit comments

Comments
 (0)