Skip to content
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

Merged
merged 1 commit into from
Oct 17, 2019

Conversation

westbury
Copy link
Contributor

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.

@svenefftinge
Copy link
Contributor

Would be great to be able to amend the initial commit. Not sure how, but maybe we can improve the git reset operation somehow?

@westbury
Copy link
Contributor Author

Would be great to be able to amend the initial commit. Not sure how, but maybe we can improve the git reset operation somehow?

This may be easier than I thought it would be. On further thought, I would not change git reset. The problem with that is that git reset would leave the repository in a state in which there is no HEAD and this could be confusing to other bits of the code that call git reset. Also git reset could be called with all sorts of different options and it would not be possible or desirable to execute git reset with all those options in any kind of consistent way while converting the repository into an empty, no HEAD, state. It's better to keep all this no-HEAD weirdness to the one place that needs it, the GitAmendSupport class.

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 amendable flag.

@westbury westbury changed the title Disable 'Amend' button when on the initial commit in the repository Allow amending of the initial commit in the repository Jul 14, 2019
@westbury
Copy link
Contributor Author

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 undefined ScmCommit or an id of undefined. This required some changes to support an undefined commit. Note that the git log command goes all the way back to the initial commit if fromRevision is not defined, which is exactly what we want. This ensures that the amending commits is restored correctly after a refresh (test by amending commits back to and including the initial commit, then refresh).

@westbury
Copy link
Contributor Author

@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.

@akosyakov akosyakov added git issues related to git scm issues related to the source control manager labels Sep 12, 2019
@kittaakos
Copy link
Contributor

@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 😊

@kittaakos
Copy link
Contributor

I have tried it with a single repository; I got a strange result when I have refreshed the browser.

Steps to reproduce:

  • Open an empty workspace.
  • Clone a Git repository.
  • Amend a few commits. Check how many commits you see.
  • Refresh the browser.
  • Check how many commits now you can see. It's more than expected.

screencast 2019-09-17 13-45-05

@westbury
Copy link
Contributor Author

I have tried it with a single repository; I got a strange result when I have refreshed the browser.

@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()) {
Copy link
Contributor

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

Copy link
Contributor Author

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.

Signed-off-by: Nigel Westbury <nigelipse@miegel.org>
@westbury
Copy link
Contributor Author

@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.

Copy link
Contributor

@kittaakos kittaakos left a 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.

@westbury westbury merged commit 1a8188f into eclipse-theia:master Oct 17, 2019
@westbury westbury deleted the GH4972 branch October 17, 2019 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
git issues related to git scm issues related to the source control manager
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Amending initial commit throws and logs exception
4 participants