-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnewfork.sh
More file actions
executable file
·33 lines (26 loc) · 1.1 KB
/
Copy pathnewfork.sh
File metadata and controls
executable file
·33 lines (26 loc) · 1.1 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
#! /bin/bash
FORKFROM=$1
FORKTO=$2
OLDREPONAME=`echo $FORKFROM | awk 'BEGIN { FS = "/" } ; { print $2 }' | awk 'BEGIN { FS = "." } ; { print $1 }'`
NEWREPONAME=`echo $FORKTO | awk 'BEGIN { FS = "/" } ; { print $2 }' | awk 'BEGIN { FS = "." } ; { print $1 }'`
if [[ -z $OLDREPONAME || -z $NEWREPONAME || $OLDREPONAME == *"/"* || $OLDREPONAME == *"github"* || $OLDREPONAME == *":"* || $NEWREPONAME == *"/"* || $NEWREPONAME == *"github"* || $NEWREPONAME == *":" ]];
then
echo "invalid repo format $OLDREPONAME $NEWREPONAME";
echo "usage: ./newfork.sh git@github.com/something/projecttofork.git git@github.com/something/newfork.git"
exit 1;
fi
if [[ -f $NEWREPONAME ]];
then
echo "folder exists";
exit 1;
fi
echo "Forking $FORKFROM to $FORKTO in folder $NEWREPONAME"
git clone $FORKFROM $NEWREPONAME || { echo "$FORKFROM not set on github, exiting" && exit 1; }
cd $NEWREPONAME
pwd
git remote set-url origin $FORKTO
git remote add upstream $FORKFROM
git push origin master || { echo "$FORKTO is not existing as a repo on github, exiting" && cd .. && rm -rf ./$NEWREPONAME/ && exit 1; }
git push --all
echo "done"
exit 0;