Created
June 29, 2021 09:49
-
-
Save comm1x/e079361a944f4624d3b90bdba47d99c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const { execSync, spawn } = require('child_process'); | |
const chalk = require('chalk'); | |
function hasChangesInRepo() { | |
return execSync('git status --porcelain').toString().length > 0; | |
} | |
if (hasChangesInRepo()) { | |
console.error('Error: there are changes in the repo. Can\'t start squashing.'); | |
return; | |
} | |
const lastCommitMessage = execSync('git log -1 --pretty=%B').toString().trim(); | |
if (!lastCommitMessage) { | |
throw new Error('Unable to get message of last commit'); | |
} | |
execSync('git reset --soft HEAD~2'); | |
spawn('git', ['commit', '-m', lastCommitMessage], {stdio:'inherit'}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment