Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Show files as conflicted in git panel when discard undo creates merge conflicts, handle various edge cases - #563

Merged
kuychaco merged 32 commits into
masterfrom
ku-show-conflicts-in-git-panel
Mar 3, 2017
Merged

kuychaco merged 32 commits into
masterfrom
ku-show-conflicts-in-git-panel

Conversation

@kuychaco

@kuychaco kuychaco commented Feb 24, 2017 •

Copy link
Copy Markdown
Contributor

Display files under conflict in Merge Conflicts list (fixes #559)
Handle removed and added file edge cases (fixes #543)
Fix bug undoing discard for file in subdirectory (fixes #588)

@kuychaco
kuychaco force-pushed the ku-show-conflicts-in-git-panel branch from 18438f1 to 97c4d4d Compare February 24, 2017 21:05
@kuychaco
kuychaco force-pushed the ku-show-conflicts-in-git-panel branch from 9e5c0f6 to 22458df Compare February 27, 2017 01:34
@kuychaco kuychaco changed the title Show files as conflicted in git panel when discard undo creates merge conflicts Show files as conflicted in git panel when discard undo creates merge conflicts, handle deleted file edge case Feb 27, 2017
Comment thread lib/models/discard-history.js Outdated
mergeResult = {filePath, resultPath, conflict: true};
}
} else if (theirsPath && !commonBasePath) { // added file
// TODO

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What will happen if this PR gets merged before this is implemented?

Comment thread lib/git-shell-out-strategy.js Outdated
`;
if (oursSha) { indexInfo += `${fileMode} ${oursSha} 2\t${filePath}\n`; }
if (theirsSha) { indexInfo += `${fileMode} ${theirsSha} 3\t${filePath}\n`; }
return this.exec(['update-index', '--index-info'], {stdin: indexInfo});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This should probably be a write op so it doesn't run in parallel with other operations.

} else if (!otherPath && basePath) { // deleted file
// TODO: handle this
return null;
const mergeFilePromises = filePaths.map(async (filePathInfo, i) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This logic is starting to feel a little hairy again. Probably okay to merge, but I continue to wonder if there are more extractions we can do, especially around object modeling. E.g. would it make sense to have a Merge object? Or utilize Conflict-style objects like in @smashwilson's conflict resolution stuff?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We couldn't use Conflict directly here (that's a conflict marker within a file, not an entire file that contains conflict markers). Introducing some kind of model for conflicted files (ConflictedFile?) might be worthwhile. Maybe we could even refactor some of the conflict resolution stuff to use it too.

Comment thread lib/models/repository.js Outdated
}

updateIndex(filePath, commonBaseSha, oursSha, theirsSha) {
return this.git.updateIndex(filePath, commonBaseSha, oursSha, theirsSha);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there a better method name than updateIndex for this? Yes, we're updating the index, but in a specific way. Perhaps writeMergeConflictToIndex or similar?

notificationManager: React.PropTypes.object,
fetch: React.PropTypes.func,
push: React.PropTypes.func,
pull: React.PropTypes.func,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a note for me to remove this same change in #565

commandRegistry={commandRegistry}
notificationManager={notificationManager}
confirm={confirm}
tooltips={tooltips}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Another note for me to remove this in #565

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😆 Yeah we all fixed this independently in our own pull requests.

@smashwilson smashwilson left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just a few bits to add.

Also: today I learned how git update-index works. That's pretty cool 😁

Comment thread lib/git-shell-out-strategy.js Outdated

async updateIndex(filePath, commonBaseSha, oursSha, theirsSha) {
const fileMode = await this.getFileMode(filePath);
let indexInfo = dedent`

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice. I was wondering if there was a library for this but I hadn't bothered to actually look for one yet 😁

} else if (!otherPath && basePath) { // deleted file
// TODO: handle this
return null;
const mergeFilePromises = filePaths.map(async (filePathInfo, i) => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We couldn't use Conflict directly here (that's a conflict marker within a file, not an entire file that contains conflict markers). Introducing some kind of model for conflicted files (ConflictedFile?) might be worthwhile. Maybe we could even refactor some of the conflict resolution stuff to use it too.

Comment thread test/git-strategies.test.js Outdated
describe('getFileMode(filePath)', () => {
it('returns the file mode of the specified file', async () => {
const workingDirPath = await cloneRepository('three-files');
const git = new GitShellOutStrategy(workingDirPath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should these use createTestStrategy?

commandRegistry={commandRegistry}
notificationManager={notificationManager}
confirm={confirm}
tooltips={tooltips}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

😆 Yeah we all fixed this independently in our own pull requests.

workdirPath = await cloneRepository('three-files');
repository = await buildRepository(workdirPath);

getFileContents = filePath => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Worth adapting into the readFile helper maybe?

@kuychaco kuychaco changed the title Show files as conflicted in git panel when discard undo creates merge conflicts, handle deleted file edge case Show files as conflicted in git panel when discard undo creates merge conflicts, handle various edge cases Mar 3, 2017
output = (await this.exec(['hash-object', '-w', filePath], {writeOperation: true})).trim();
} catch (e) {
output = null;
if (e.stdErr.match(/fatal: Cannot open .*: No such file or directory/)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍

@kuychaco
kuychaco merged commit fec0f20 into master Mar 3, 2017
@kuychaco
kuychaco deleted the ku-show-conflicts-in-git-panel branch March 3, 2017 16:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Undo Discard is broken Update index for conflicts on restoration of discarded changes Error when discarding lines in removed file

3 participants