]> git.phdru.name Git - git-scripts.git/commitdiff
Merge fork-existing into fork
authorOleg Broytman <phd@phdru.name>
Sat, 19 Aug 2017 19:08:33 +0000 (22:08 +0300)
committerOleg Broytman <phd@phdru.name>
Wed, 23 Aug 2017 05:40:13 +0000 (08:40 +0300)
fork
fork-existing [deleted file]

diff --git a/fork b/fork
index 64a281c2df31895b28a076401cef1f3087402fe4..2c8d82a780fea20a4d5816b15ac9346425091a2a 100755 (executable)
--- a/fork
+++ b/fork
@@ -9,16 +9,24 @@ upstream="$1"
 origin="$2"
 local_repo="`basename \"$origin\" .git`"
 
 origin="$2"
 local_repo="`basename \"$origin\" .git`"
 
-git clone -o upstream "$upstream" "$local_repo" &&
-cd "$local_repo" &&
+if [ -d "$local_repo"/.git ]; then
+   cd "$local_repo" &&
+   git remote add upstream "$upstream" &&
+   git remote set-url origin "$origin"
+else
+   git clone -o upstream "$upstream" "$local_repo" &&
+   cd "$local_repo" &&
+   git remote add origin "$origin"
+fi &&
+
 pwd >> "`dirname \"$0\"`"/locate-all.list &&
 pwd >> "`dirname \"$0\"`"/locate-all.list &&
-git remote add origin "$origin" &&
 
 chmod a-x .git/config &&
 
 chmod a-x .git/config &&
-branch="`git branch | awk '/^\*/ {print $2}'`" &&
+branch="`git rev-parse --abbrev-ref HEAD`"
 
 
+git pull upstream $branch &&
 git pull origin $branch &&
 git pull origin $branch &&
-git push -u origin &&
+git push -u origin $branch &&
 
 git config branch.$branch.remote upstream &&
 git config branch.$branch.remotepush origin &&
 
 git config branch.$branch.remote upstream &&
 git config branch.$branch.remotepush origin &&
diff --git a/fork-existing b/fork-existing
deleted file mode 100755 (executable)
index 20e4685..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-#! /bin/sh
-
-if [ -z "$2" ]; then
-   echo "Usage: $0 upstream origin" >&2
-   exit 1
-fi
-
-upstream="$1"
-origin="$2"
-
-pwd >> "`dirname \"$0\"`"/locate-all.list &&
-git remote add upstream "$upstream" &&
-git remote set-url origin "$origin" &&
-
-chmod a-x .git/config &&
-branch="`git branch | awk '/^\*/ {print $2}'`" &&
-
-git pull origin $branch &&
-git push -u origin &&
-
-git config branch.$branch.remote upstream &&
-git config branch.$branch.remotepush origin &&
-git config branch.$branch.merge refs/heads/$branch &&
-git config push.default current &&
-
-exec git gc --aggressive