Skip to content

Commit 2fb495c

Browse files
committed
feat: add force push option
1 parent ebdf401 commit 2fb495c

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ Keep reading for more cool stuff like:
111111
| `INCLUDE_WEEKENDS` | A boolean indicating whether or not to make commits on weekends. | `true` | |
112112
| `MIN_COMMITS_PER_DAY` | The minimum integer number of commits to make per day (inclusive). Used by a pseudo-RNG. | `1` | |
113113
| `MAX_COMMITS_PER_DAY` | The maximum integer number of commits to make per day (inclusive). Used by a pseudo-RNG. | `1` | |
114+
| `FORCE_PUSH` | A boolean indicating whether or not to force push. **WARNING:** Setting this to `true` will clear out your repo on each run! | `false` | |
114115

115116
### Advanced environment variables 🧙‍♂️
116117

src/index.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import fs from 'fs/promises';
12
import git from 'simple-git/promise';
23
import subDays from 'date-fns/fp/subDays';
34
import getUnixTime from 'date-fns/fp/getUnixTime';
@@ -21,6 +22,7 @@ const {
2122
INCLUDE_WEEKENDS = true,
2223
MIN_COMMITS_PER_DAY = 1,
2324
MAX_COMMITS_PER_DAY = 1,
25+
FORCE_PUSH = false,
2426
} = process.env;
2527

2628
const repoPath = `https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@${GIT_HOST}/${GITHUB_REPOSITORY}`;
@@ -29,7 +31,14 @@ const secondLine = 'Committed via https://github.com/marketplace/actions/autopop
2931
const dayOffsets = [...Array(Number(MAX_DAYS)).keys()];
3032
const originDay = fromUnixTime(ORIGIN_TIMESTAMP);
3133

32-
await git().clone(repoPath, localPath, ['--single-branch', '-b', GIT_BRANCH]);
34+
await fs.mkdir(localPath);
35+
36+
if (JSON.parse(FORCE_PUSH)) {
37+
await git(localPath).init();
38+
} else {
39+
await git().clone(repoPath, localPath, ['--single-branch', '-b', GIT_BRANCH]);
40+
}
41+
3342
await git(localPath).env({GIT_SSH_COMMAND});
3443
await git(localPath).addConfig('user.name', GITHUB_ACTOR);
3544
await git(localPath).addConfig('user.email', GIT_EMAIL);
@@ -51,4 +60,4 @@ await dayOffsets
5160
.flat()
5261
.reduce((commitPromises, nextPromise) => commitPromises.then(nextPromise), Promise.resolve());
5362

54-
await git(localPath).push(repoPath, GIT_BRANCH);
63+
await git(localPath).push(repoPath, GIT_BRANCH, JSON.parse(FORCE_PUSH) && {'--force': null});

0 commit comments

Comments
 (0)