Prevent overwriting manual changes made to branch#341
Prevent overwriting manual changes made to branch#341alecsammon wants to merge 1 commit intoBetaHuhn:masterfrom
Conversation
| await execCmd( | ||
| `git checkout -b "${ newBranch }"`, | ||
| `git remote set-branches origin '*'`, | ||
| this.workingDir | ||
| ) | ||
|
|
||
| this.prBranch = newBranch | ||
| await execCmd( | ||
| `git fetch -v --depth=1`, | ||
| this.workingDir | ||
| ) |
There was a problem hiding this comment.
The code currently only checks out the default branch. We need to fetch the other branches so we can switch to as required.
| ) | ||
|
|
||
| await execCmd( | ||
| `git switch "${ newBranch }" 2>/dev/null || git switch -c "${ newBranch }"`, |
There was a problem hiding this comment.
Attempt to switch to the existing branch, if this doesn't exists (i.e. no PR already exists) then create a new branch.
| async getCommitsToPush() { | ||
| const output = await execCmd( | ||
| `git log --format=%H --reverse ${ SKIP_PR === false ? `` : `origin/` }${ this.baseBranch }..HEAD`, | ||
| `git log --format=%H --reverse ${ this.lastCommitSha }..HEAD`, |
There was a problem hiding this comment.
base the commits on the difference from the last pushed commit to now.
This is safe as this reference is not updated until the
for (const commit of commits) {
await this.createGithubCommit(commit)
}
that follows.
| // A wrapper for running all the flow to generate all the pending commits using the GitHub API | ||
| async createGithubVerifiedCommits() { | ||
| core.debug(`Creating Commits using GitHub API`) | ||
| core.debug(`Creating commits using GitHub API`) |
There was a problem hiding this comment.
commit/commits are not capitalised elsewhere in this code.
| if (FORK) { | ||
| return execCmd( | ||
| `git push -u fork ${ this.prBranch } --force`, | ||
| `git push -u fork ${ this.prBranch } --force-with-lease`, |
There was a problem hiding this comment.
--force-with-lease adds an extra layer of security for preventing overwrite of changes when using the git push instead of the github API.
We use the
repo-file-sync-actionfor a number of tasks including syncing changes to our linting configuration.When we make an update to the linting rules then manual changes are often required in addition to the synced file.
Currently if the sync action runs again then it overwrites any changes make in other files, including all the history.
This PR will adjust this, so that the existing PR is updated instead, and the changes added as a new commit.