Skip to content

Handle fast-forward merges properly in repository.performRebase#1457

Merged
implausible merged 3 commits intonodegit:masterfrom
cjhoward92:fix/rebase-ff-merge
Mar 16, 2018
Merged

Handle fast-forward merges properly in repository.performRebase#1457
implausible merged 3 commits intonodegit:masterfrom
cjhoward92:fix/rebase-ff-merge

Conversation

@cjhoward92
Copy link
Collaborator

@cjhoward92 cjhoward92 commented Mar 12, 2018

Rebases currently expect the rewritten file to exist when a rebase occurs and a beforeFinishFn is specified. This is not the case when the rebase results in a fast-forward merge as nothing is rewritten.

@cjhoward92
Copy link
Collaborator Author

@implausible

@rcjsuen
Copy link
Member

rcjsuen commented Mar 12, 2018

Can we get a test added for this?

Will this also fix #1318?

@cjhoward92
Copy link
Collaborator Author

I'll try and add a test. Yes, it will fix that issue.

@cjhoward92 cjhoward92 changed the title Handle fast-forward merges in repository.performRebase Handle fast-forward merges properly in repository.performRebase Mar 13, 2018
*/
function readRebaseMetadataFile(fileName, determineExistance) {
const fullPath = path.join(repository.path(), "rebase-merge", fileName);
if (determineExistance && !fse.existsSync(fullPath)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use the async version of exists.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because of how promisify-node turns callbacks into promises, fse.exists has a bug where you need to call .catch to actually get the value you would expect from .then so it looks really horrible and is a bit confusing if you ask me. Either that or I can use the callback version, which I don't want to do either. That being said, I don't think the asynchronous version will really gain us anything in this instance so I would rather avoid adding

fse.exists(fillPath).catch(result => /* do work here */).then()

to this code block. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What bug is this in promisify-node and why can't we fix that there and then improve this code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not be promisify-node as the issue, depending on how you look at it. exists has one callback argument. promisify-node assumes that first argument is an error and the second argument is the value returned. exists doesn't adhere to nodejs callback best practices.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That being said we can bump fse as later versions seem to have fixed this issue, from what I understand, or we can use a different function all together, like stat or access or something something.

The node documentation recommends we just run a read on the file and catch the error, which can also work.

@implausible implausible merged commit 60ffb34 into nodegit:master Mar 16, 2018
@cjhoward92 cjhoward92 deleted the fix/rebase-ff-merge branch March 16, 2018 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants