setup_project.sh: Add optional branch argument.

Add an optional branch argument to setup_project.sh that determines
which branch to grab the local manifest from for the sync. Needed
when working on, for example, factory and firmware branches.

BUG=b:168828175
TEST=used with non master branch checkout of chromiumos/config

Change-Id: Ia0032fc2ec150cf889b135d258bab0d484771ae8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/config/+/2426121
Commit-Queue: David Burger <dburger@chromium.org>
Reviewed-by: Andrew Lamb <andrewlamb@chromium.org>
(cherry picked from commit c14e20f9319362a0c0173f63bb84c255f83b6a94)
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/config/+/2425969
Reviewed-by: Andrew McRae <amcrae@chromium.org>
Commit-Queue: Andrew McRae <amcrae@chromium.org>
diff --git a/setup_project.sh b/setup_project.sh
index 7f87448..915dc2c 100755
--- a/setup_project.sh
+++ b/setup_project.sh
@@ -19,10 +19,16 @@
 }
 
 function usage() {
+<<<<<<< HEAD   (580839 cl_factory launcher: Extract out csv_param method.)
   echo "Usage: $0 <program> [<project>]" >&2
   echo "  for setups with a single repo for the program with" >&2
   echo "  projects in subdirectories, only the program argument" >&2
   echo "  is provided." >&2
+=======
+  echo "Usage: $0 <program> <project> [<branch>]" >&2
+  echo "  optionally pass branch to sync the project" >&2
+  echo "  from the local manifest at the given branch." >&2
+>>>>>>> CHANGE (c14e20 setup_project.sh: Add optional branch argument.)
   exit 1
 }
 
@@ -40,6 +46,7 @@
 readonly program="${1}"
 # Will be empty if this is a single program repository project.
 readonly project="${2}"
+readonly branch="${3}"
 
 readonly local_manifests_dir="../../.repo/local_manifests"
 
@@ -76,7 +83,12 @@
 # a confusing error message from being shown to the user. The
 # --force-sync below actually causes it to not be a problem, but we'd
 # rather avoid the user having to interpret the error.
-git clone "${clone_url}" "${clone_src}"
+if [[ -z "${branch}" ]]; then
+  git clone "${clone_url}" "${clone_src}"
+else
+  git clone "${clone_url}" "${clone_src}" --branch "${branch}"
+fi
+
 find "${clone_src}" -mindepth 1 ! -name local_manifest.xml -exec rm -rf {} +
 
 if [[ ! -d  "${local_manifests_dir}" ]]; then