]> git.phdru.name Git - git-scripts.git/blobdiff - fork
Feat(fork): Check .git in the current directory
[git-scripts.git] / fork
diff --git a/fork b/fork
index 99a84766258911f57c08a9c73ddc9fcd346161d9..2f032d54a6acf572e19f9007321e7fc16a4c331f 100755 (executable)
--- a/fork
+++ b/fork
@@ -9,20 +9,31 @@ upstream="$1"
 origin="$2"
 local_repo="`basename \"$origin\" .git`"
 
-git clone -o upstream "$upstream" "$local_repo" &&
-cd "$local_repo" &&
-git remote add origin "$origin" &&
+if [ -d "$local_repo"/.git ]; then
+   cd "$local_repo"
+fi &&
+
+if [ -d .git ]; then
+   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 &&
 
 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 push -u origin &&
+git push -u origin $branch &&
 
 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 &&
 
-git gc --aggressive &&
-exec pwd >> "`dirname \"$0\"`"/locate-all.list
+exec git gc --aggressive