forked from plume-lib/plume-scripts
-
Notifications
You must be signed in to change notification settings - Fork 4
/
git-find-fork
executable file
·42 lines (34 loc) · 1.28 KB
/
git-find-fork
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh
###
### This script has been moved to the git-scripts repository:
### https://github.com/plume-lib/git-scripts
###
echo "Please use $(basename "$0") from https://github.com/plume-lib/git-scripts ."
echo "You are using $0,"
echo "which is an obsolete version from https://github.com/plume-lib/plume-scripts ."
# find-git-fork: finds a fork of a GitHub repository, or returns the upstream
# repository if the fork does not exist.
# Usage: find-git-fork ORG UPSTREAM_ORG REPONAME
# Prints the first one of these that exists:
# https://github.com/${ORG}/${REPO}.git
# https://github.com/${UPSTREAM_ORG}/${REPO}.git
# Often, you can use the `git-clone-related` script instead of this one.
if [ "$#" -ne 3 ]; then
script=$(basename -- "$0")
>&2 echo "Error: $script requires 3 arguments, got $#"
>&2 echo "Usage: $script ORG UPSTREAM_ORG REPONAME"
exit 1
fi
ORG=$1
UPSTREAM_ORG=$2
REPONAME=$3
# Problem with "git ls-remote": it may ask for GitHub credentials.
# (It also downloads more information than wget does.)
# export GITEXISTS="git ls-remote"
export GITEXISTS="wget -q --spider"
if ( ${GITEXISTS} "https://github.com/${ORG}/${REPONAME}.git" > /dev/null ); then
OWNER="${ORG}"
else
OWNER="${UPSTREAM_ORG}"
fi
echo "https://github.com/${OWNER}/${REPONAME}.git"