Friday 8 June 2018

Version Control in VS for Mac - How to select certain changes made from a branch into another via the Merge process...

Version Control in VS for Mac
Selectively choose the changes you want to be in the new branch when trying to merge from other branch via stage and unstage method. 


Scenario: 

Your branches:
One Master branch.
One Staging branch. 

Assumption:
You treat master branch as your daily development branch. 
Both branches have a same file called 'Detail.xaml'. 
You plan to merge some changes done master branch into your staging branch. 

Ok... let's start: 


1) 
Add a new line in detail.xaml. e.g.: 
<Label Text="This line is for master only"/>
The commit it,. and push it to master branch. 

2)
Add another line in detail.xaml (underneath the label) . e.g: 
<Label Text="This line is for master only"/>
<Label Text="This line is for staging only"/> <----- div="" line.="" nbsp="" new="">Then, commit it, and push it to master branch. 


3)
Add another line in detail.xaml .e.g:
<Label Text="This line is for master only"/>
<Label Text="This line is for staging only"/>
<Label Text="This new line is for master only"/> <----- div="" line.="" nbsp="" new="">
Then, commit it, and push it to master branch. 

With the above changes done on master branch, you should have something looks like this in your git view: 



Merge my changes into Staging

1. I switch my branch to staging first. Then click on the merge button. This will allow me choose 'Merge from Log' or 'Merge Fetched'.  (I am not clear what is the differences between these). 

I usually go for 'Merge from log',  so that I can choose the changes via log view. 
See the image below (note! I will untick the 'Commit merge immediately'):


2. Click OK,. then,.. check out the File Status on the left menu: 
Click on the File Status. 
Click on the file name. 
Right click the line in source code window. 
Choose 'Unstage selected line'. 


3. Once you have done the steps as above (After onstage a selected line),.. 
Your file will fall into 'Unstage file' section:
highlight the line you want DO NOT to be merged into staging.
Right click, then choose 'Discard selected line'. 


4. Two lines have been discarded from the source:




5. Move your file from 'Unstaged File' back to 'Staged File' by clicking on the check box next to the file name in 'Unstraged File' section. 

6. Then.. remember you need to COMMIT your file first. 
And finally PUSH your change to remote staging. 

Job done.  Double check the changes from the source code.  
And,  both the staging and master branches are in the same development line now: 

Done!
---




Thursday 7 June 2018

Version Control in VS for Mac

Version Control in VS for mac together with Sourcetree.


It is also a painful experience when you try to use the Version Control from VS for Mac. Some people even describe it as a junk. I would say, it is sufficient to do a common stuff such as check out, commit, push, view logs, blame,.. but not Merge.  It is a basic tool which you might encounter a lot of issue when you need to manage multiple branch, merging the changes from different branches, as well as resolve the conflict and so on.  Right, this article is not able how good or bad it is. It is all about how to use it together with SourceTree. 

Well,
Pre-requisition
1) Your remote repository URL.
Let's start with the assumption that you already have a remote repository setup somewhere, either in GitHub, or VSTS, etc.  Mine is in VSTS.  Get ready your remote repository URL by just clicking on the clone button from your remote repository portal site first. 

2) Install Sourtree from the following website:  https://www.sourcetreeapp.com
Get an account from sourcetree. Just to ensure you are allow to you the tool. Do not connect to any of its given hosted account (remote Git repo, such as BitBucket, GitHub, etc).  (Unless you haven't had any remote repo yet). 



PART1: 

1) First thing first, Setup A local repository
a) I started with create empty folder called "MyTestProject" in my local machine. This will become my project folder that going to match with the project in remote repo.

b) In SourceTree window,  click on 'Local'. 
Note: 'Remote' will basically allow you to create a connection to hosted account such as BitBucket, etc) 

Instead of choosing 'Clone from URL', start with 'Add existing Local Repository'.
In this case, I will choose the folder I just created "MyTestProject".
Immediately after this, you will see a prompt with title 'Create a local repository' window. 
Keep whatever setting it is,.. then click 'Create' button. 

Done! You have the local repo setup.  (Later on, this will be the project folder you need when you are in VS.) 




2) Next, Link your local repository to the remote repository
a) Double click on the project name 'MyTestProject' from the above image. This will load another window on the screen: 




b) Setup the remote repository:  Click on the 'Repository' tab from the main window bar. Then choose 'Repository Settings'. After that choose 'Remotes'. See the image as below. And, finally click on 'Add' button. 


c) Provide a remote name and the URL. (The clone URL from the remote repo). 

d)Now, you have your remote repo setup. To your remote repo,...  
Mouse over the REMOTES menu on the left, click on the little 'show' menu next to it.  (It toggle in between show and hide).


At this point, you may have noticed there is no branches listed under the BRANCHES menu.  
And, there is nothing under the 'REMOTES' menu apart from my project name. 
So,. the next action will be... 

e) Fetch your branches from remote repo. At this point, we haven't check out all file from the remote branch yet!
Right click the project name.  (My case will be... right click on the 'MyFirstProject'.. then choose 'Fetch from my FirstProject'. ) Due to the reason I already have 2 branches exists in my remote repo (1 called master, and another one called staging), therefore I have 2 listed under my project. 


f) Checkout remote branch...  (check out all the files to you local repo).


g) Once you've done the above step. You should see your branch appear in 'BRANCHES' menu:
Right, this will be your working copy. 
Double check the check out files from your Finder.  You should have a copy of your remote file in your project folder now. 

Part 2: 

Continue the setup in VS for Mac

In Part 2, what we try to achieve is to make use of the existing version control, to work together with the version control from SourceTree.  It will ultimately produce a result where when you finished changing a file, you may either commit it via VS or SourceTree.  Or, you can even push the committed files from VS or SourceTree.  Wait... why we want to do that? 

Well, when it comes to a situation where you think you like to merge or resolve some of the code conflict,.. instead of using the Version Control from VS for Mac,  I will recommend you to use SourceTree to resolve it.  That's the whole point. 

a) As usual, open you project solution via VS. First of all you shall see the branch name next to your solution name. Example: HelloWorld (master). 

b) Click on version control --> Manage branches and remotes,  then goto 'Remote sources tab'. 

Click on Edit,.. paste the same URL that you got it from the Clone URL. 
Next, Track the branch... :


c) Setup Braches as well (If Not mistaken, this is for local repo). 

Right all done!!



Part 3: 

The magic in between SourceTree and Version Control


If you keep the source tree open,  click on a branch under the 'BRANCHES' menu, will auto reflect the selected branch in VS.  Try it... 

Right,...
VS allow you to switch the branch from one to anther. For my case,.. I should be allowed to Switch from Master to Staging. However, I am hitting this error: 

'Branch Switch Failed'.
String cannot be empty. 
Parameter name: name. 

To resolve this issue,..you have to make a changes to a file, commit it and push it.  Then, this will be resolved automatically. 




Part 4: Resolve conflict. 

Whenever you hit a conflict,  click on the conflict file, the choose external tool 'FileMerger' to resolve it.  
Remember, here is the step to resolve:
1. Choose which line you want, choose the action from the dropdown list. 
The Left window is your changes. The right window is others. 

2. Save it before you mark it as resolve. 

3. Must mark it as resolve. 



Wednesday 9 May 2018

Xamarin - Create Launch Screen for iOS

Before iOS 8, creating a launch screen for an iOS app required the developer to provide an image asset for each of the various device from factors and resolutions in which the app could run. Therefore, you may ask you designer to come out different size of images base on official spec.

With the new Launch screen, you are recommended to use StoryBoard. Use the iOS designer to add image view and label to the storyboard, and set the constraints on those views, and to verify that looks correct for various devices, etc.

Right,...the most common problem:

Why all the images used in launch story board not appear in device? 


Right,.. after few minutes of research and testing, here are the solutions:

1. In your iOS project, double click the 'assets.xcassets' folder.  Then you will see:
- AppIcon
- LaunchImage

2. Right click on the white space, choose create new image set.  Note: you can create as many image set you like. E.g. If you going to use 2 images in the launch story board, then you probably need two image set.

3. Upload your image to 1x, 2x and 3x. (Not sure what R4 is...)

4. In your Info.plist / under the iPhone Launch Images:
- Source: None (because you are not going to use anything from 'launchImage'.
- Launch Screen:  will be your launchScreen.Storyboard.

5. This step is the most important step!!  Within your launchScreen.storyboard,.. all the image used within this board should be just the file name, with NO extension.  E.g.: if you have image named 'logo@2x.png' ,   then, please use 'logo', that's all.

6. Just incase if the image still not appear, please make sure there are set to bundle resource in resources folder.

Last things last...
if still not appear, do this as well:

"I was messing around with this for hours too. But i found the solution now. You need to add the image to your project and also to the asses.xcassets via drag and drop." 



How to run unit test for your Xamarin Application in AppCenter?

How to run unit test for your Xamarin application in AppCenter?  When we talk about Building and Distributing your Xamarin app, you m...