-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgit-find-fork
More file actions
executable file
·40 lines (34 loc) · 1.22 KB
/
git-find-fork
File metadata and controls
executable file
·40 lines (34 loc) · 1.22 KB
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
#!/bin/sh
# git-find-fork: finds a fork of a GitHub repository, or returns the upstream
# repository if the fork does not exist.
# Usage: git-find-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_NAME=$(basename -- "$0")
>&2 echo "Error: ${SCRIPT_NAME} requires 3 arguments, got $#"
>&2 echo "Usage: ${SCRIPT_NAME} 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` or `curl` does.)
# export GITEXISTS="git ls-remote"
if command -v wget > /dev/null; then
export GITEXISTS="wget -q --spider"
elif command -v curl > /dev/null; then
export GITEXISTS="curl --output /dev/null --silent --head --fail --location"
else
echo "git-find-fork: Neither wget nor curl is installed" >&2
exit 2
fi
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"