A script for downloading git library code, git library script

Source: Internet
Author: User

A script for downloading git library code, git library script

Because of the daily building requirement, you need to use a script to download the code for automatic compilation. This script is a small part of the function of the entire system.



#!/bin/bash#@author Liuyang#@date 2015-06-23function help() {    echo "Usage: $0"    echo "    First argument should be the git repository's address"    echo "        for example: git@192.168.1.52:android/xiaomeidaojia.git"    echo "    Second argument should be the branch you want to checkout"    echo "        for example: dev"    echo "    If the second argument is not supplied, master will be used as default"}# Whether the given branch is in local branches.function is_in_local_branch() {    git branch | grep $1 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>&1 > /dev/null    return $?}if [[ $# != 1 && $# != 2 ]]; then    help    exit 1fi# Judge whether the repository's address is valid.if [[ $1 != *.git ]]; then    help    exit 1fi# Split the project's nameproject_name=`echo $(basename $1) | cut -d . -f 1`if [[ ! -d $project_name ]]; then    git clone $1else    cd $project_name    git reset HEAD --hard    git pull    if [[ $2 == "" ]]; then        exit    fi    is_in_local_branch $2    if [[ $? == 0 ]]; then        git checkout $2        exit    fi    is_in_remote_branch $2    if [[ $? == 0 ]]; then        git checkout -b $2 origin/$2    fifi



In the script, first determine whether the git library exists. If it does not exist, clone the repository.

Otherwise, all changes will be rolled back, the pull operation will be executed, and the given branch will be switched.


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.