-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Allow amending of the initial commit in the repository #5451
Conversation
Would be great to be able to amend the initial commit. Not sure how, but maybe we can improve the |
This may be easier than I thought it would be. On further thought, I would not change Don't review this PR yet. After #5484 is merged I'll amend this PR. If the initial commit is amendable then we don't need the |
I have now re-written this to allow the amending of the initial commit. There is no need to ever disable the amend button because once the initial commit has been amended there is no head commit and hence no 'amend' button. There are no Git commands that I could find to reset a repository to before the initial commit. However one can get back to the same state (the state immediately after 'git init') by deleting refs/heads/master. Actually it reads HEAD to find the branch as the user could have changed the branch from master. There is no SHA that represents the state before the first commit, so that state is represented in this PR by |
@kittaakos I was wondering if you had time to have a look at this one. It's left over from the work on the Git/SCM/VsCode switchover a few months ago. |
@westbury, thanks for the reminder. I am a little bit out of the Theia loop recently, but I will find some time to get this done. Also, I owe you a review for the output logging for Electron 😊 |
I have tried it with a single repository; I got a strange result when I have refreshed the browser. Steps to reproduce:
|
@kittaakos thank you for testing and for finding the problem. The problem you have found is caused by commits that have multiple parents, as you are amending merge commits. When you press 'amend', it picks the first parent so you see a linear list of commits. However when you refresh you are seeing all the commits on all paths from the new head to the original head. This does need to be fixed, and I will come up with a fix. However this problem is separate from this issue which covers the handling of the initial commit. The problem occurs in master so perhaps should be covered by a separate PR. |
@@ -413,7 +416,23 @@ export class GitAmendSupport implements ScmAmendSupport { | |||
} | |||
|
|||
public async reset(commit: string): Promise<void> { | |||
await this.git.exec(this.repository, ['reset', commit, '--soft']); | |||
if (commit === 'HEAD~' && await this.isHeadInitialCommit()) { |
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.
In VS Code they seem to be able to handle this without using the filesystem.
https://github.com/microsoft/vscode/blob/master/extensions/git/src/commands.ts#L1464
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.
In VS Code they seem to be able to handle this without using the filesystem
@svenefftinge you are totally correct. git update-ref -d HEAD
does the trick perfectly. Thanks for pointing that out. It tests fine. I have amended the commit accordingly.
cfec8f5
to
5322e24
Compare
Signed-off-by: Nigel Westbury <nigelipse@miegel.org>
@kittaakos Are you able to re-verify this PR? The last change was to replace the use of file-system with the git update-ref command. |
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.
I have verified the change-set in Gitpod, it worked. I could amend to the initial commit of the repo.
This fixes #4972
This fix is not a high priority as the problem has always existed. However I thought I would submit the fix so that we don't keep finding the problem or wondering if this is the cause of other issues.
To test this, use a repository with few commits and amend back to the initial commit. One should not be able to amend the initial commit.