IOS Code Review (Code Review for iOS), iosreview

Source: Internet
Author: User
Tags git mergetool

IOS Code Review (Code Review for iOS), iosreview

IOS code review

(Code Review for iOS)

The iOS app development team is using Gerrit for code review. The following instructions assume you're using a recent version of Mac OS X.

Contents [hide]
  • 1 New to Git?
  • 2 Activate your code review account
  • 3 Get the code onto your machine
  • 4 Make changes and request a code review
  • 5 Update your code
  • 6 When Gerrit Fails to Submit Due to Merge Errors
  • 7 When The Code Won't Run
  • 8 Git Tips and Tricks
    • 8.1Squash multiple commits into one
    • 8.2Get rid of uncommitted changes
    • 8.3Reset your git repository to match the public repository
    • 8.4Set up difftool and mergetool
New to Git?

If you are new to Git I suggest you take the time to read the first three chapters of the official git book, this will simplify your life later.

If you don't read it now, at least come back to it after you are thoroughly frustrated with Git.

Here is a link to an introduction to the Gerrit Code Review tool.

We have come up with a Common Workflow that will help you be more productive and avoid common pitfalls. Please read and follow it.

Here is

Activate your code review account
  1. Sign in to the code review website with your LDS Account.
  2. Ask an admin for access to the project.
Get the code onto your machine
  1. If you haven't already done so, set up password caching.
  2. Clone the project you're working on (be sure to replace "PROJECT" in this and all further instructions with the name of the actual project you're working on ). use your LDS Account password for this step (password caching makes it so you only have to use this password once ):
    git clone https://tech.lds.org/mobile/codereview/p/PROJECT
  3. Clone any libraries the project uses. Not all projects have them, but it doesn't hurt. Use your LDS account credentials for this step.
    cd PROJECTgit submodule update --init --recursive
  4. Set up a commit hook. this hook will automatically add the appropriate change ID to every commit. the change ID will help the code review tool to group multiple commits as a single change. this aids the back and forth process of polishing the code until it is ready to be committed to the master repository. if you skip this step, you'll be unable to push, but it won't be obvious why.
    curl https://tech.lds.org/mobile/codereview/tools/hooks/commit-msg > .git/hooks/commit-msgchmod u+x .git/hooks/commit-msg
  5. ConfigureGit pushCommand to request a code review. If you skip this step, you'll be unable to push.
    git config remote.origin.push HEAD:refs/for/master
  6. Set up your name and email. The email will need to match what you have registered in LDS Tech. If you skip this step, you'll be unable to push any commits you make.
    git config --global user.name "Your Name"git config --global user.email "your@email.address"

    If you have already committed with the wrong information, you can:

    git commit --amend --author="Author Name <email@address.com>"
    If there are multiple commits with the wrong information, follow these more in-depth steps.
Make changes and request a code review
  1. Make sure you're on branch master:
    git checkout master
  2. Make sure you're working with the latest code:
    git pull origin master
  3. Create a new branch for your changes:
     git checkout -b <branchname>
  4. Make your changes.
  5. Verify your changes:
    git diffgit status
  6. Commit your changes locally:
    git commit -a

    You'll be asked to enter a commit message. Use the following format:

    (PROJECT-245) Short summary of change (~50 chars max, issue ID in parentheses if applicable)A more elaborate summary of the committed changes and suggested tests.May have bullet points or paragraphs. Break at 72 chars. This is shownwhen users view the full commit.
  7. Request a code review:
    git push
    You will be asked for your username (LDS Account username) and password (LDS Account password ).

We recommend you use git credential caching, here's how you set up git to cache your username and password.

Update your code

The code review process exists to maintain a high level of code quality, to make sure that more than one set of eyes has seen every line of code, and to provide an opportunity for both the contributor and the reviewer to learn. it is rare that any code review request does not require some change, even if minor. when that happens:

  1. Checkout the submitted code review.
    • Find the "Download" option by going to your submitted code in Gerrit (the code review tool) and scrolling down to the latest patch set.
    • Make sure the "Checkout" and "HTTP" options above the command are selected.
    • CopyGit fetch https...Line next to "Download" and execute it in your terminal.
  2. Make your changes. Note: Make sure you don't rebase your change, as that makes it impossible to view only the differences in gerrit.
  3. Verify your changes:
    git diffgit status
  4. Commit and request another code review. Do not use-MArgument for commit as this will overwrite the change ID. Update the commit description in the editor.
    git commit -a --amendgit push
When Gerrit Fails to Submit Due to Merge Errors

If you get the error "Your change cocould not be merged due to a path conflict" when submitting a change set in the code review tool, you need to resolve the conflict by following these steps:

  1. Make sure your master branch is up to date:Git pull origin master
  2. Checkout the conflicting change set. You can copy/paste the correct command from the 'Download' section in the code review tool. It will look something like:Git fetch https: // hiltonc@tech.lds.org/mobile/codereview/PROJECT refs/changes/08/8/2 & git checkout FETCH_HEAD
  3. Rebase against master (this shoshould give you a conflict warning. this is OK !) :Git rebase master
  4. If you haven't already done so, set up your mergetool (see related section in Tips and Tricks ).
  5. RunGit mergetoolTo resolve the conflicts. Save and close each file.
  6. Tell the rebase to continue now that the issue is resolved:Git rebase -- continue
  7. Push the resolved conflict for review:Git push
  8. Re-review the change set in the code review tool, and then submit the changes to be merged to master.
When The Code Won't Run

Please build/run problems can be solved by doing one or all of the following:

  1. In the git repository, runGit submodule update -- init -- recursive
  2. In the iOS Simulator click on "iOS Simulator"-> "Reset Content and Settings ..."
  3. In Xcode, type command-option-shift-k (or alternately, hold down option while selecting "Product"-> "Clean ")
Git Tips and TricksSquash multiple commits into one
  1. Supply the parent of the last commit you want to edit (for example 3 ):
    git rebase -i HEAD~3
    (That's dash I and tilde 3)
  2. You shoshould see a list of commits in your text editor you'll want to change the commits you 'd like to squash from 'pick' to's ;:
    pick f7f3f6d changed my name a bits 310154e updated README formatting and added blames a5f4a0d added cat-file
  3. Save and exit your text editor
    :wq
  4. All your commit messages will then be shown. Combine them into one message, making sure you only have one change-id.
  5. Magic happens! And your commits are squashed.
  6. If the short version above isn't sufficient for your purposes, you can visit the link for more details. Learn about interactive rebasing for more details (specifically the section about squashing commits ).
Get rid of uncommitted changes

WARNING: This will lose all of your uncommitted or unstashed changes.

To get rid of uncommitted changes, performGit reset -- hard HEAD.

If you want to get rid of them temporarily, doGit stash.

Reset your git repository to match the public repository

WARNING: These steps will get rid of all of your unpublished changes on the branch you perform this on, even if they have been committed to that branch. (If they have been committed to a separate branch or stashed (Google "git stash"), they shocould be fine, but be careful .)

If you get into a state that you don't like and you want to blow away your changes and get to a clean state, follow these steps on your preferred branch (most likely branch master):

  1. Get rid of unwanted commits by sort MingGit reset -- hard HEAD ~ <Number>. Replace <number> with a value slightly more than the number of unwanted commits you want to get rid of. For instance, if you see from yourGit logThat you have 3 commits you want to blow away, thenGit reset -- hard HEAD ~ 5Wocould do the trick. (Note the tilde)
  2. Update to public repository state by DemingGit pull origin master.

If this doesn't work, use one of the destructive blunt instruments described on Stack Overflow.

Set up difftool and mergetool

Git config -- global diff. tool opendiff

Git config -- global merge. tool opendiff

By default, mergetool keeps ". orig" backup files. To disable this, runGit config -- global mergetool. keepBackup false.

This page was last modified on 4 December 2013, at. This page has been accessed 6,903 times.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.