]> gitweb.fluxo.info Git - scripts.git/commitdiff
Adding git_folder into commit script
authorSilvio Rhatto <rhatto@riseup.net>
Mon, 14 Jan 2013 20:55:43 +0000 (18:55 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Mon, 14 Jan 2013 20:55:43 +0000 (18:55 -0200)
commit

diff --git a/commit b/commit
index 3e417d248d01e26e397a399d0e25cdf25b50f5cf..a113432fd486ea51171bb99c1d54308da6640b3e 100755 (executable)
--- a/commit
+++ b/commit
@@ -3,23 +3,77 @@
 # Commit both on git and svn
 #
 
+# Get the absolute folder from a file
+# Usage: absolute_folder <file>
+function absolute_folder {
+
+  local file="$1" cwd
+
+  if [ -e "$file" ]; then
+    cwd="`pwd`"
+    cd `dirname $file`
+    pwd
+    cd $cwd
+  fi
+
+}
+
+# Check if a file is inside a git repository
+# Usage: git_folder <file>
+function git_folder {
+
+  local file="$1" folder folders dir_list cwd
+
+  if [ -e "$file" ]; then
+    folder="`absolute_folder $file`"
+  fi
+
+  if [ -d "$folder/.git" ]; then
+    GIT_FOLDER="$folder"
+    return
+  fi
+
+  # reverse folder order
+  dir_list="`echo $folder | tr '/' ' '`"
+  for i in $dir_list; do
+    folders="$i $folders"
+  done
+
+  cwd="`pwd`"
+  cd $folder
+
+echo folders: $folders
+  for i in $folders; do
+    cd ..
+    if [ -d "$(pwd)/.git" ]; then
+      cd $cwd
+      GIT_FOLDER="$(pwd)"
+      return true
+    fi
+  done
+
+  cd $cwd
+  return 1
+
+}
+
 # Check if a folder is inside a git repository
 function is_git {
   # simple git folder checker
   # usage: is_git <folder>
   if [ -z "$1" ]; then
-    false
+    return 1
   elif [ ! -d "$1" ]; then
-    false
+    return 1
   elif [ -d "$1/.git" ]; then
-    true
+    return
   else
     ( cd "$1" && git status &> /dev/null )
     
     if [ "$?" != "128" ]; then
-      true
+      return
     else
-      false
+      return 1
     fi
   fi
 }
@@ -49,7 +103,7 @@ function git_push {
 
 # Check user information
 function git_user {
-  if ! grep -q "^\[user\]" .git/config; then
+  if ! grep -q "^\[user\]" $GIT_FOLDER/.git/config; then
     echo "No user configuration section found in the repository."
     echo "This might be a privacy issue"
 
@@ -70,6 +124,7 @@ if [ ! -z "$1" ]; then
   fi
 
   if is_git .; then
+    git_folder $(pwd)
     git_user
     git commit -a -m "$*"
     git_push