Thursday 2 February 2017

Keeping your Haven and Hearth client up to date

Every once in a while things get updated and after some time you might end up seeing something like:
Obviously you won't be able to login as long as your client is too old. And this is where we need to make sure we properly track upstream Amber client branch we forked.

How did we fall behind?

First of all - lets figure out how did it happen that we fell behind? To do so lets have a look at our GitHub repo (the one we created back here - https://winter-in-hnh.blogspot.ru/2017/01/haven-and-hearth-client.html when we forked Amber repository from romovs):
As you can see above our current branch is 45 commits behind master branch of romovs Amber repository. To see what has changed you can click on "Compare" button, make sure to select your fork as base, and romovs/amber as head, you should see something something like the following:
Here you can see the list of all 45 commits that we've missed so far, and in "Files changed" tab we will be able to see all  files that were changed. One thing to note - is that GitHub currently is not aware of changes we've done - all the changes we were doing so far (https://winter-in-hnh.blogspot.ru/2017/01/extending-haven-and-hearth-client.html and https://winter-in-hnh.blogspot.ru/2017/01/lets-add-buttons.html) were pretty much invisible for GitHub - we were doing all of them locally in our local git environment. So before we get into merging upstream changes, lets commit out own changes.

Commiting changes

To commit changes - right-click your project name in "Project Explorer" select "Team" and then "Commit":
This will bring up "Staging" tab - where you will be presented with changes that you've done so far - select all the files you've changed and write a commit message.
Make sure that you "Commit and Push" your changes - commit will only commit changes to your local repository, while Push, will also get them to remote - GitHub one. Once completed we should see our changes on GitHub:

Unfortunately we can no longer automatically merge, because our changes conflict with some of the changes done to upstream.

How do we merge?

Ok, so we are not at the stage when we would really want to push anything to Amber, so we'll need to change our changes to co-exist with what was modified. There are two GitHub articles that describe what we are going to do next:
So lets follow this guides. First of all lets check what our current local repository is bound to:
Nothing surprising here - this is the repository we created forking romovs/amber and cloned locally to build and modify our Haven and Hearth client (as described in https://winter-in-hnh.blogspot.ru/2017/01/haven-and-hearth-client.html). Now lets add an "upstream" repository:
With "upstream" set we can now fetch content from it:
Let's make sure we are on the "master" branch of our "origin":
Since we expect some merging problems lets use Eclipse IDE merging tool.
What we are planning to do, is to merge our Local repository and 'upstream/master' branch and then commit it to our remote 'origin/master', so first thing to do here is to configure what we will be merging:
So we have conflicts - conflicting places are marked in "Project Explorer" and can be identified in source by special tokens:
So lets start the "Merge tool" and fix our conflicts:
Once complete you should see a "Merged master" message next to your project name in "Project Explorer":
Now it's time to commit our merge the same way we commited our changes in the beginning of the article.

Observing consequencies

Once evertyhing is commited and pushed lets have a look at where we end up. On GitHub we now can compare romovs/amber repository as base to our repository as HEAD:

According to GitHub comparation we are two commits ahead - and that is exactly where we would want to be - ahead of our upstream. Lets try to compile the result.. and it works!

Well done!

If we don't frequently sync to upstreams - we fall behind and the time would come when a change is done to the client that obsoletes our working copy forcing us to re-sync. The further away we are from current state of upstream client - the more is probability that we'll have to merge conflicting changes - so we should be catching up with upstream as frequent as possible to avoid complex merges.

On high level merging is pretty simple:
  1. Make sure you have your upstream repository configured
  2. Fetch changes from your configured upstream repository
  3. Make sure you are on the "master" branch of your forked repository
  4. Merge the changes
  5. If you are lucky - all changes would be a simple fast-forward, if not - resolve conflicts
  6. Rebuild the project
  7. Enjoy







No comments:

Post a Comment