Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Support union merges via .gitattributes file #3497

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

Closed

Conversation

stanhu
Copy link
Contributor

@stanhu stanhu commented Oct 31, 2015

When a repository has a .gitattributes file that has a merge=union line for a CHANGELOG file, for example, libgit2 ignores this file and reports a conflict when git doesn't have one. This is partially to fix #2180.

I tried adding a test for this, but adding .gitattributes file to the merge-resolve directory seems to cause additional failures due to the change in entries. I wanted to get feedback on this before spending even more time on that.

@@ -1712,6 +1733,10 @@ int git_merge__iterators(
git_vector_foreach(&changes, i, conflict) {
int resolved = 0;

/* Check for merge options in .gitattributes */
if ((error = git_merge__lookup_file_favor(repo, conflict->our_entry.path, &opts) < 0))
Copy link

Choose a reason for hiding this comment

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

Since this modifies opts in place, won't the newly set opts->file_favor bleed into conflict resolution for other files, processed after the file that had the attribute set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, good point. I've updated the code to not do that.

@stanhu stanhu force-pushed the use-gitattributes-for-union-merge branch 2 times, most recently from 94f140f to 6859aca Compare November 3, 2015 07:25
@dblessing
Copy link

Is there anything else needed on this PR? Please let us know if we can help.

@ethomson
Copy link
Member

Sorry about the delay! A couple of things, most are stylistic and minor:

  1. We like to put our out-type parameters to the function up front. Eg, something more like:

    static int git_merge__lookup_file_favor(
        int *file_favor,
        git_repository *repo,
        const char *path)
    
  2. Regarding function naming, those that are fully "namespaced" with double underscores (eg, git_merge__function) are meant to be internal to the entire library. (As opposed to those that are fully namespaced with single underscores, like git_merge_files, which are public API.) For a simple static helper function like this, it should not be namespaced, and something like lookup_file_favor would be more appropriate.

  3. It looks like the configuration file_favor option overrides the option specified by the caller. This should be the other way around: the configuration should override the git_merge_file_favor_t in the merge options if the options did not specify a side to favor (eg, file_favor == GIT_MERGE_FILE_FAVOR_NORMAL). However, if the options did specify a side to favor, then that should override any configuration setting.

  4. Fundamentally, it would be nice to support more than just this one option to the merge attribute (eg, binary, text, etc). I don't know that this necessarily needs to be done in this pull request, but I feel like it would actually affect the architecture more fundamentally. (You would likely find that the file_favor is not the appropriate way to report this data, for example.) So this might be something that you find valuable to explore, I don't know.

@stanhu stanhu force-pushed the use-gitattributes-for-union-merge branch 2 times, most recently from ee96e34 to 18f9489 Compare November 18, 2015 22:41
@stanhu
Copy link
Contributor Author

stanhu commented Nov 19, 2015

Thanks, @ethomson. I've updated the PR based on your comments. I actually think the right way to support different merge attributes would be to implement custom merge drivers as mentioned in #2180 so that conflicts never actually surface here, but this seemed like an easier change to support the CHANGELOG case in the short term.

I did attempt to write a test for this case, but because I added a .gitattributes file to one of the test repositories, that seemed to have break other tests. I'm not sure what the best way to proceed there.

@ethomson
Copy link
Member

Neat! I think that the easiest way to test this would be to create a test that writes the gitattributes file before doing the merge. (As you point out - a lot of the other tests depend on the current state of those test repositories.)

You should be able to do something as simple as:

cl_git_mkfile("merge-resolve/.gitattributes", "*.cs merge=union\n");

(Replacing the path and contents with something more appropriate.)

@stanhu stanhu force-pushed the use-gitattributes-for-union-merge branch from 1977b65 to 9e9b6d2 Compare November 26, 2015 06:32
@stanhu
Copy link
Contributor Author

stanhu commented Nov 26, 2015

Thanks for the tip, @ethomson! I've updated the PR with a test.

@stanhu stanhu force-pushed the use-gitattributes-for-union-merge branch from 9e9b6d2 to 001d4c8 Compare December 1, 2015 08:50
@stanhu stanhu force-pushed the use-gitattributes-for-union-merge branch from 001d4c8 to 6d4b5c1 Compare December 1, 2015 08:55
@stanhu
Copy link
Contributor Author

stanhu commented Dec 3, 2015

@ethomson, would you mind taking a look? Thank you.

@stanhu
Copy link
Contributor Author

stanhu commented Dec 3, 2015

Somehow my test case vanished when I rebased. Working on that...

@stanhu
Copy link
Contributor Author

stanhu commented Dec 3, 2015

Ok, fixed. Looks like the rebase introduced a bug that prevented this functionality from working that was caught by the test.

@DouweM
Copy link

DouweM commented Dec 9, 2015

@ethomson Friendly reminder to review this pull request :)

@ethomson
Copy link
Member

Hi - sorry about the delay. Thanks so much for the fine work here.

As I reviewed this, I must admit that I felt very bad that we were going to open up merge=union as an attribute but only merge=union. This seemed begging for the custom merge driver support that #2180 had requested and been so patiently waiting for.

As a result, I opened #3564 that includes this as well as merge=<custom> support for custom merge drivers.

Thanks again!

@stanhu
Copy link
Contributor Author

stanhu commented Dec 26, 2015

@ethomson Thanks for implementing custom merge support--even better! I suppose we can close this PR then?

@ethomson
Copy link
Member

Sounds good, I rolled both these commits into that PR, so I'll go ahead and close this one.

Thanks again for the fine work.

@ethomson ethomson closed this Dec 26, 2015
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.

Custom merge driver support
4 participants