-
-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent overwriting manual changes made to branch #341
base: master
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Attempt to switch to the existing branch, if this doesn't exists (i.e. no PR already exists) then create a new branch.
@@ -304,7 +326,7 @@ export default class Git { | |||
// Gets the commit list in chronological order | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -321,7 +343,7 @@ export default class Git { | |||
|
|||
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commit
/commits
are not capitalised elsewhere in this code.
@@ -366,15 +390,15 @@ export default class Git { | |||
async push() { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--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-action
for 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.