LoginSignup
1
0

More than 1 year has passed since last update.

ubuntuでシェルスクリプトを使って.gitが存在するディレクトリのリポジトリURLを取得する

Posted at

ubuntuでシェルスクリプトを使って.gitが存在するディレクトリのリポジトリURLを取得する

以下でOKのはず

test.sh
#!/bin/bash                                                                                                                                          

GIT_DIRECTORY=`find . -name .git`
RESULT_ARR=()
for dir in ${GIT_DIRECTORY}
do
    echo "--- directory"
    echo ${dir}
    echo "--- "
    pushd ${dir}
    REPOSITORY_URL=`git remote -v | grep fetch | cut -f2 | cut -d' ' -f1`
    popd
    STR="${dir}@${REPOSITORY_URL}"    # 区切り文字を仮で@にしている事に注意                                                                          
    RESULT_ARR+=("${STR}")
done

echo "--- result"
for i in ${RESULT_ARR[@]}
do
    echo ${i}
done

テスト

$ bash test.sh
./http/icecream/.git@https://github.com/seigot/icecream
# 区切り文字を仮で@にしている事に注意                                   
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0