From 4cdce8caa74728a4973261dae0e00fcd479af9ac Mon Sep 17 00:00:00 2001 From: Alex Forencich Date: Mon, 15 Jul 2019 14:55:10 -0700 Subject: [PATCH] Add subtree scripts --- fpga/lib/update-axi.sh | 118 ++++++++++++++++++++++++++++++++++++++++ fpga/lib/update-eth.sh | 118 ++++++++++++++++++++++++++++++++++++++++ fpga/lib/update-pcie.sh | 118 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 354 insertions(+) create mode 100755 fpga/lib/update-axi.sh create mode 100755 fpga/lib/update-eth.sh create mode 100755 fpga/lib/update-pcie.sh diff --git a/fpga/lib/update-axi.sh b/fpga/lib/update-axi.sh new file mode 100755 index 000000000..23fc76d43 --- /dev/null +++ b/fpga/lib/update-axi.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# Git subtree manager +# Alex Forencich +# This script facilitates easy management of subtrees +# included in larger repositories as this script can +# be included in the repository itself. + +# Settings +# uncomment to use --squash +#squash="yes" +# Remote repository +repo="git@github.com:alexforencich/verilog-axi.git" +# Remote name +remote="axi" +# Subdirectory to store code in +# (relative to repo root or to script location) +#subdir="axi" +rel_subdir="axi" +# Remote branch +branch="master" +# Backport branch name (only used for pushing) +backportbranch="${remote}backport" +# Add commit message +addmsg="added ${remote} as a subproject" +# Merge commit message +mergemsg="merged changes in ${remote}" + +# Usage +# add - adds subtree +# pull - default, pulls from remote +# push - pushes to remote + +# determine repo absolute path +if [ -n "$rel_subdir" ]; then + # cd to script dir + SOURCE="${BASH_SOURCE[0]}" + while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + done + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + + cd "$DIR" + + # relative path to script dir + git-absolute-path () { + fullpath=$(readlink -f "$1") + gitroot="$(git rev-parse --show-toplevel)" || return 1 + [[ "$fullpath" =~ "$gitroot" ]] && echo "${fullpath/$gitroot\//}" + } + + subdir="$(git-absolute-path .)/$rel_subdir" +fi + +squashflag="" + +cd $(git rev-parse --show-toplevel) + +if [ $squash ]; then + squashflag="--squash" +fi + +action="pull" + +if [ ! -d "$subdir" ]; then + action="add" +fi + +if [ -n "$1" ]; then + action="$1" +fi + +# array contains value +# usage: contains array value +function contains() { + local n=$# + local value=${!n} + for ((i=1;i < $n;i++)) { + if [ "${!i}" == "${value}" ]; then + echo "y" + return 0 + fi + } + echo "n" + return 1 +} + +case "$action" in + add) + if [ $(contains $(git remote) "$remote") != "y" ]; then + git remote add "$remote" "$repo" + fi + git fetch "$remote" + git subtree add -P "$subdir" $squashflag -m "$addmsg" "$remote/$branch" + ;; + pull) + if [ $(contains $(git remote) "$remote") != "y" ]; then + git remote add "$remote" "$repo" + fi + git fetch "$remote" + git subtree merge -P "$subdir" $squashflag -m "$mergemsg" "$remote/$branch" + ;; + push) + if [ $(contains $(git remote) "$remote") != "y" ]; then + git remote add "$remote" "$repo" + fi + git subtree split -P "$subdir" -b "$backportbranch" + git push "$remote" "$backportbranch:$branch" + ;; + *) + echo "Error: unknown action!" + exit 1 +esac + +exit 0 + diff --git a/fpga/lib/update-eth.sh b/fpga/lib/update-eth.sh new file mode 100755 index 000000000..05512c669 --- /dev/null +++ b/fpga/lib/update-eth.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# Git subtree manager +# Alex Forencich +# This script facilitates easy management of subtrees +# included in larger repositories as this script can +# be included in the repository itself. + +# Settings +# uncomment to use --squash +#squash="yes" +# Remote repository +repo="git@github.com:alexforencich/verilog-ethernet.git" +# Remote name +remote="eth" +# Subdirectory to store code in +# (relative to repo root or to script location) +#subdir="eth" +rel_subdir="eth" +# Remote branch +branch="master" +# Backport branch name (only used for pushing) +backportbranch="${remote}backport" +# Add commit message +addmsg="added ${remote} as a subproject" +# Merge commit message +mergemsg="merged changes in ${remote}" + +# Usage +# add - adds subtree +# pull - default, pulls from remote +# push - pushes to remote + +# determine repo absolute path +if [ -n "$rel_subdir" ]; then + # cd to script dir + SOURCE="${BASH_SOURCE[0]}" + while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + done + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + + cd "$DIR" + + # relative path to script dir + git-absolute-path () { + fullpath=$(readlink -f "$1") + gitroot="$(git rev-parse --show-toplevel)" || return 1 + [[ "$fullpath" =~ "$gitroot" ]] && echo "${fullpath/$gitroot\//}" + } + + subdir="$(git-absolute-path .)/$rel_subdir" +fi + +squashflag="" + +cd $(git rev-parse --show-toplevel) + +if [ $squash ]; then + squashflag="--squash" +fi + +action="pull" + +if [ ! -d "$subdir" ]; then + action="add" +fi + +if [ -n "$1" ]; then + action="$1" +fi + +# array contains value +# usage: contains array value +function contains() { + local n=$# + local value=${!n} + for ((i=1;i < $n;i++)) { + if [ "${!i}" == "${value}" ]; then + echo "y" + return 0 + fi + } + echo "n" + return 1 +} + +case "$action" in + add) + if [ $(contains $(git remote) "$remote") != "y" ]; then + git remote add "$remote" "$repo" + fi + git fetch "$remote" + git subtree add -P "$subdir" $squashflag -m "$addmsg" "$remote/$branch" + ;; + pull) + if [ $(contains $(git remote) "$remote") != "y" ]; then + git remote add "$remote" "$repo" + fi + git fetch "$remote" + git subtree merge -P "$subdir" $squashflag -m "$mergemsg" "$remote/$branch" + ;; + push) + if [ $(contains $(git remote) "$remote") != "y" ]; then + git remote add "$remote" "$repo" + fi + git subtree split -P "$subdir" -b "$backportbranch" + git push "$remote" "$backportbranch:$branch" + ;; + *) + echo "Error: unknown action!" + exit 1 +esac + +exit 0 + diff --git a/fpga/lib/update-pcie.sh b/fpga/lib/update-pcie.sh new file mode 100755 index 000000000..f74e3ad25 --- /dev/null +++ b/fpga/lib/update-pcie.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +# Git subtree manager +# Alex Forencich +# This script facilitates easy management of subtrees +# included in larger repositories as this script can +# be included in the repository itself. + +# Settings +# uncomment to use --squash +#squash="yes" +# Remote repository +repo="git@github.com:alexforencich/verilog-pcie.git" +# Remote name +remote="pcie" +# Subdirectory to store code in +# (relative to repo root or to script location) +#subdir="pcie" +rel_subdir="pcie" +# Remote branch +branch="master" +# Backport branch name (only used for pushing) +backportbranch="${remote}backport" +# Add commit message +addmsg="added ${remote} as a subproject" +# Merge commit message +mergemsg="merged changes in ${remote}" + +# Usage +# add - adds subtree +# pull - default, pulls from remote +# push - pushes to remote + +# determine repo absolute path +if [ -n "$rel_subdir" ]; then + # cd to script dir + SOURCE="${BASH_SOURCE[0]}" + while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + SOURCE="$(readlink "$SOURCE")" + [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located + done + DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )" + + cd "$DIR" + + # relative path to script dir + git-absolute-path () { + fullpath=$(readlink -f "$1") + gitroot="$(git rev-parse --show-toplevel)" || return 1 + [[ "$fullpath" =~ "$gitroot" ]] && echo "${fullpath/$gitroot\//}" + } + + subdir="$(git-absolute-path .)/$rel_subdir" +fi + +squashflag="" + +cd $(git rev-parse --show-toplevel) + +if [ $squash ]; then + squashflag="--squash" +fi + +action="pull" + +if [ ! -d "$subdir" ]; then + action="add" +fi + +if [ -n "$1" ]; then + action="$1" +fi + +# array contains value +# usage: contains array value +function contains() { + local n=$# + local value=${!n} + for ((i=1;i < $n;i++)) { + if [ "${!i}" == "${value}" ]; then + echo "y" + return 0 + fi + } + echo "n" + return 1 +} + +case "$action" in + add) + if [ $(contains $(git remote) "$remote") != "y" ]; then + git remote add "$remote" "$repo" + fi + git fetch "$remote" + git subtree add -P "$subdir" $squashflag -m "$addmsg" "$remote/$branch" + ;; + pull) + if [ $(contains $(git remote) "$remote") != "y" ]; then + git remote add "$remote" "$repo" + fi + git fetch "$remote" + git subtree merge -P "$subdir" $squashflag -m "$mergemsg" "$remote/$branch" + ;; + push) + if [ $(contains $(git remote) "$remote") != "y" ]; then + git remote add "$remote" "$repo" + fi + git subtree split -P "$subdir" -b "$backportbranch" + git push "$remote" "$backportbranch:$branch" + ;; + *) + echo "Error: unknown action!" + exit 1 +esac + +exit 0 +