A script that downloads git library code

Source: Internet
Author: User

Because of the daily build requirements, you need to download the code with a script to automate the compilation, which is a small piece of functionality throughout the system.



#!/bin/bash# @author liuyang# @date 2015-06-23function Help () {echo ' Usage: $ "echo" first argument should be th e git repository ' s address "echo" For example: [Email protected]:android/xiaomeidaojia.git "echo" s Econd argument should be the branch you want to checkout "echo" for Example:dev "echo" If the second AR Gument is not supplied, master would be used as default "}# Whether the given branch are in local branches.function Is_in_loc Al_branch () {git branch | grep $2>&1 >/dev/null return $?} # Whether The given branch is in remote Branches.function is_in_remote_branch () {git branch-r | grep origin/$1 2>& Amp;1 >/dev/null return $?} if [[$#! = 1 && $#! = 2]]; Then help exit 1fi# Judge whether the repository's address is valid.if [[$! = *.git]]; Then help exit 1fi# Split The project ' s Nameproject_name= ' echo $ (basename $) | Cut-d. -F 1 ' if [[!-D $project _name]]; Then git ClonE $1else cd $project _name git reset HEAD--hard git pull if [[[$ = =]]; Then exit fi is_in_local_branch if [[$? = = 0]]; Then git checkout $ exit fi is_in_remote_branch $ IF [[$ = = 0]]; Then git checkout-b $ origin/$2 Fifi



In the script, first determine if the GIT library exists and does not exist to clone the repository.

Otherwise, all changes are rolled back, then the pull operation is performed, and the final switch to the given branch.


A script that downloads git library code

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.