由于每日构建需求, 须要用脚本下载代码, 实现自己主动化编译, 这个脚本是整个系统的一小块功能

#!/bin/bash

#@author Liuyang
#@date 2015-06-23 function 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 1
fi # Judge whether the repository's address is valid.
if [[ $1 != *.git ]]; then
help
exit 1
fi # Split the project's name
project_name=`echo $(basename $1) | cut -d . -f 1` if [[ ! -d $project_name ]]; then
git clone $1
else
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
fi
fi

脚本中, 首先推断该git库是否存在, 不存在则克隆该仓库.

否则会回退全部更改, 然后运行拉取操作, 最后会切换到给定分支.

一个下载git库代码的脚本的更多相关文章

  1. GIT库代码管理规范

    GIT库代码管理规范 一. 规范要求 1. 每个项目建立单独的GIT库.每个GIT库包括两条线,命名规则如下: 开发线(测试):项目名称_DEV 生产线(正式):项目名称 2. 每条线只允许增量不允许 ...

  2. Jenkins一个任务下载多个git库代码

    公司的项目是微服务架构,一个服务对应的一个git仓库,现在的需求时拉取所有仓库代码下来,指定父级的pom.xml,一次性构建打包 jenkins在默认情况下,一个任务只能配置一个git仓库地址 1.安 ...

  3. 其他:Git生成SSH、Git生成本地库、下载远程库代码 命令

    1.安装Git Bash https://git-scm.com/downloads 2.鼠标右键git bash here 3.执行以下命令: ①   cd ~/.ssh/    [如果没有对应的文 ...

  4. 将已有Git库代码推送到新建库中

    cd /path/to/your/git/repo/ git remote -v git remote rm origin git remote add origin ssh://abc@gmail. ...

  5. 使用快盘托管Git库

    Dropbox非常好用.可是我如今也没弄明确究竟哪里好用了.不如试试中国的金山快盘..起码不会操心被墙. cd ~/Kuaipan/repo git --bare init //初始化仓库 cd ~/ ...

  6. Eclipse 安装配置和 Git 创建代码库 教程

    1. Eclipse 安装 http://www.eclipse.org/downloads/ 这是eclipse的官网,进入下载,步骤如下图: 选择Download或者下面的 [Select Ano ...

  7. iOS 推荐一个下载用的第三方库

    AFNetworking有下载功能,但是下载功能比较基本,要实现复杂下载功能需要自己写一些代码.今天在github上找到了一个下载功能的开源项目,非常不错,链接如下:https://github.co ...

  8. git远程库代码版本回滚方法

    最近使用git时, 造成了远程库代码需要回滚到之前版本的情况,为了解决这个问题查看了很多资料. 问题产生原因: 提交了错误的版本到远程库. 以下是解决的方法, 供大家参考: 1.对本地代码库进行回滚 ...

  9. 毕加索的艺术——Picasso,一个强大的Android图片下载缓存库,OkHttpUtils的使用,二次封装PicassoUtils实现微信精选

    毕加索的艺术--Picasso,一个强大的Android图片下载缓存库,OkHttpUtils的使用,二次封装PicassoUtils实现微信精选 官网: http://square.github.i ...

随机推荐

  1. [jquery] ajax parsererror

    http://stackoverflow.com/questions/5061310/jquery-returning-parsererror-for-ajax-request 方法一: 直接去掉 d ...

  2. HDU 6333.Problem B. Harvest of Apples-组合数C(n,0)到C(n,m)求和-组合数学(逆元)+莫队 ((2018 Multi-University Training Contest 4 1002))

    2018 Multi-University Training Contest 4 6333.Problem B. Harvest of Apples 题意很好懂,就是组合数求和. 官方题解: 我来叨叨 ...

  3. UESTC 30.最短路-最短路(Floyd or Spfa(链式前向星存图))

    最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) 在每年的校赛里,所有进入决赛的同 ...

  4. UVA 11624 Fire!【两点BFS】

    Joe works in a maze. Unfortunately, portions of the maze have caught on fire, and the owner of the m ...

  5. 单词接龙(dragon)(BFS)

    单词接龙(dragon) 时间限制: 1 Sec  内存限制: 64 MB提交: 12  解决: 5[提交][状态][讨论版] 题目描述 单 词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已 ...

  6. 推荐下载CentOS下各种组件的网址

    http://vault.centos.org/ ftp://mirrors.sohu.com/ http://mirror.webtatic.com/

  7. luogu P1126 机器人搬重物

    题目描述 机器人移动学会(RMI)现在正尝试用机器人搬运物品.机器人的形状是一个直径1.6米的球.在试验阶段,机器人被用于在一个储藏室中搬运货物.储藏室是一个N*M的网格,有些格子为不可移动的障碍.机 ...

  8. AOJ 2251 Merry Christmas (最小点覆盖)

    [题目链接] http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2251 [题目大意] 给出一张图,现在有一些任务,要求在ti时刻送礼物 ...

  9. 【2-SAT】Codeforces Round #403 (Div. 2, based on Technocup 2017 Finals) D. Innokenty and a Football League

    先反复地扫(不超过n次),把所有可以确定唯一取法的给确定下来. 然后对于剩下的不能确定的,跑2-SAT.输出可行解时,对于a和¬a,如果a所在的强连通分量序号在¬a之前,则取a,否则不取a.如果a和¬ ...

  10. 【二分答案】【最大流】bzoj3993 [Sdoi2015]星际战争

    二分Time,S->炮[i]:Time*b[i] 炮[i]->机器人[i]:INF 机器人[i]->T:a[i]. 判断是否满流. #include<cstdio> #i ...