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

Pull #464

Merged
merged 53 commits into from
Sep 9, 2015
Merged

Pull #464

merged 53 commits into from
Sep 9, 2015

Conversation

phatblat
Copy link
Member

Initial Pull implementation preferring fast-forward merge if possible or a "normal" merge if branches have diverged, depending on the merge analysis. Pull will fail if a conflict is detected.

TODO

  • Fast-forward merge
  • Normal merge
  • Merge conflict communication to caller (via error)
  • Tests

Out of scope

  • Pull with rebase
  • Explicit merge commit (aka --no-ff)
  • Prevent merge commit (aka --ff-only)
  • Pull an unborn branch

@pietbrauer
Copy link
Member

Slightly more elegant than what I had: https://gist.github.com/pietbrauer/b1b3d2c6bd927ac85094

Things with open question marks for me:

  • How to fast forward (shell out to libgit2?) to avoid merge commit
  • How to support rebase (I guess libgit2 needs rebase support first?)
  • How to deal with merge conflicts (or how to communicate them back to the caller)

@pietbrauer
Copy link
Member

I also end up with a dirty working copy when trying to pull in 2 commits from the remote:

Phone is at pietbrauer/git2go-test-repo@02ed2a3
Remote is at pietbrauer/git2go-test-repo@7c17c58

diff --git a/Test.txt b/Test.txt
index 5948f52..34f55f5 100644
--- a/Test.txt
+++ b/Test.txt
@@ -26,5 +26,3 @@ Test 25
 Test 26
 Test 27
 Test 28
-Test 29
-Test 30

Can you confirm?

@palmin
Copy link

palmin commented Jun 17, 2015

My insights are for raw libgit2 but I will outline how I merge and perhaps this can be applied in objective-git.

For me git_merge_analysis is key to getting good merges in the second step of a push.

I start out getting merge heads for HEAD and corresponding head on remote tracking branch. These merge heads are git_annotated_commit in libgit2. Then I use git_merge_analysis to determine if fast-forward is possible, if HEAD is unborn (without any previous commits) or if we need to perform a regular merge.

fast-forward and unborn HEAD is fixed by pointing to the head commit of the remote tracking branch with git_reference_set_target but the real work lies in regular merge of course.

The regular merge changes the tree and I use git_index_has_conflicts to check for conflicts. When there are none I can simply make the merge commit having the old HEAD and remote tracking head commits as parents.

If there are conflicts these need to be resolved by the user somehow and git_index_remove_bypath followed by git_index_add_bypath is used to mark a file as resolved and when everything is resolved a commit can proceed.

Hope this helps in some small way.

Working Copy does not currently do rebase but it should be a matter of applying git_cherrypick on the commits that the remote tracking branch is ahead.

@pietbrauer
Copy link
Member

@palmin Thanks so much for sharing your insights!

@phatblat I added GitMergeAnalysis support and will try to add support for Fast-Forward.


// Check if merge is necessary
GTBranch *localBranch = [repo currentBranchWithError:error];
if (*error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should be checking for the return value, not the error — I fear a nice SEGV if I was to pass NULL here. There are other cases below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. Using the user-supplied error pointer for control flow is messy, and dangerous 💥 .

@phatblat
Copy link
Member Author

Wow, great info @palmin! Thanks!

@pietbrauer
Copy link
Member

@phatblat I just added a draft for unborn and fast forward merges. Seems to work. Although I end up with staged changes, the history seems to be the same as on the remote. success_kid.gif

@palmin
Copy link

palmin commented Jun 18, 2015

Regarding changes after using git_reference_set_target to fast-forward:
I need to use git_checkout_head to get the working copy in order.

@pietbrauer
Copy link
Member

@palmin Thanks once again. Done so in 1a2fd36

@phatblat
Copy link
Member Author

@pietbrauer did you create a new referenceByUpdatingTarget:committer:message:error: method on GTReference? The logic after analyseMerge gets called is looking for that method and not finding it.

@phatblat
Copy link
Member Author

If libgit2 doesn't support rebase then I think it's clear that's out of scope for this PR.

@pietbrauer
Copy link
Member

@phatblat Ups, looks like I used objective-git ~> 0.6.2 in my project. I updated the implementation in 0bd6b02

What else is missing now?

@pietbrauer
Copy link
Member

@phatblat The core problem is that travis aborts builds if they take longer than 10 minutes and produce no output. They increased it recently (that is why we added Travis again).

One possible workaround would be to trigger ./script/update_libssh2 manually before starting xctool. The reason is because the scripts produce output while running but xctool is omitting the output, until the script finished (which is after about 11 minutes).

@phatblat
Copy link
Member Author

Ah. Those library build scripts could also be changed to inline the output instead of dumping it into architecture-specific log files (perhaps with an optional verbose flag).

Those log files have been troubling me since they make it hard to watch the build as it runs. Also, libgit2 build outputs hundreds of warnings for the 32-bit arm architectures (not sure how big an issue that is), but that's not easily visible since it's all tucked away out of sight. I realize there's a lot of output from those builds, but Xcode hides it all as soon as that build step completes successfully.

@phatblat
Copy link
Member Author

phatblat commented Aug 8, 2015

Merged a handful of changes from master mostly just to kick off another build

});

/// Conflict During Merge
it(@"fails to merge whene there is a conflict", ^{

Choose a reason for hiding this comment

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

s/whene/when/g

@phatblat
Copy link
Member Author

phatblat commented Aug 9, 2015

Oops. Thx @modocache!

I guess it wasn't the 🔥 that was causing the Failed to query the list of test cases in the test bundle: Error while parsing JSON: The data is not in the correct format. error on Travis. It's got to be something in the tests in the /pull branch because our other PRs aren't having this problem.

@phatblat
Copy link
Member Author

The build for this PR is finally green! Turns out disabling a test using pending causes Travis to choke.

Ready for review.

});
});

/* pending tests break build on travis
Copy link
Member

Choose a reason for hiding this comment

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

lol 😭

@joshaber
Copy link
Member

joshaber commented Sep 8, 2015

Sorry I'm a scumbag and waited too long to review this 😞. It looks good other than needing to be updated.

# Conflicts:
#	ObjectiveGitFramework.xcodeproj/project.pbxproj
@phatblat
Copy link
Member Author

phatblat commented Sep 8, 2015

No worries! I've updated from master. I'd like to request a pull of the Pull pull request. 😆

@joshaber
Copy link
Member

joshaber commented Sep 9, 2015

I'd like to request a pull of the Pull pull request.

@joshaber
Copy link
Member

joshaber commented Sep 9, 2015

🤘

joshaber added a commit that referenced this pull request Sep 9, 2015
@joshaber joshaber merged commit 90dacb6 into master Sep 9, 2015
@joshaber joshaber deleted the pull branch September 9, 2015 14:08
@dleehr
Copy link
Contributor

dleehr commented Sep 9, 2015

Awesome! 🎉

@joshaber joshaber mentioned this pull request Apr 6, 2016
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants