Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

git-merge-up & git-submodule-helper works with referenced git repos

  • Loading branch information...
commit 9767796f987fbeafbf5c4bed514399c06b3e6a1f 1 parent 2ada8e0
Tim Harper authored
Showing with 25 additions and 11 deletions.
  1. +11 −6 git-merge-up
  2. +14 −5 git-submodule-helper
17 git-merge-up
View
@@ -12,17 +12,22 @@ def run(cmd)
true
end
+git_directory =
+ case
+ when File.file?(".git")
+ File.read(".git").gsub("gitdir: ", "").strip
+ when File.directory?(".git")
+ ".git"
+ else
+ puts "You must run this command from the root directory of a git repository"
+ exit 1
+ end
DEFAULT_PATH=%w[master,staging,next]
merge_path = %x{git config mergeup.path || echo #{DEFAULT_PATH}}.chomp.split(",")
-current_branch = %x{cat .git/HEAD}.strip.gsub("ref: refs/heads/", "")
+current_branch = File.read("#{git_directory}/HEAD").strip.gsub("ref: refs/heads/", "")
puts "current branch is #{current_branch}"
-unless File.directory?(".git")
- puts "You must run this command from the root directory of a git repository"
- exit 1
-end
-
unless %x{git diff}.strip.empty?
puts "You have existing changes. Stash them and rerun."
exit 1
19 git-submodule-helper
View
@@ -28,8 +28,8 @@ submodule_md5 () {
submodule_stash_path () {
local path="$1"
- [ ! -d ".git/submodule_cache/" ] && mkdir .git/submodule_cache
- printf ".git/submodule_cache/`submodule_md5 "$path"`"
+ [ ! -d "$GIT_DIR/submodule_cache/" ] && mkdir "$GIT_DIR/submodule_cache"
+ printf "$GIT_DIR/submodule_cache/`submodule_md5 "$path"`"
}
submodule_helper_stash () {
@@ -83,7 +83,7 @@ submodule_helper_stash_status () {
}
submodule_helper_attach () {
- if (cat .git/HEAD | grep ref: 1> /dev/null) ; then
+ if (cat $GIT_DIR/HEAD | grep ref: 1> /dev/null) ; then
echo "You're already on a branch"
return 1
fi
@@ -98,7 +98,7 @@ submodule_helper_attach () {
rev=$(echo $line | awk '{print $1}')
ref=$(echo $line | awk '{print $3}')
if ( echo $ref | egrep '^refs/heads/' > /dev/null ); then
- echo "ref: $ref" > .git/HEAD
+ echo "ref: $ref" > $GIT_DIR/HEAD
return 0
fi
@@ -137,6 +137,10 @@ submodule_helper_add_folder () {
pushd $folder > /dev/null
url=$(git config remote.origin.url)
popd > /dev/null
+ if [ -z "$url" ]; then
+ echo "Repository in $folder does not have remote named origin."
+ exit 1
+ fi
git submodule add "$url" "$folder"
}
@@ -221,7 +225,12 @@ DISCLAIMER: Make sure you back things up first in case things go horribly wrong
EOF
}
-if [ ! -d ".git" ]; then
+GIT_DIR=".git"
+if [ -f "$GIT_DIR" ]; then
+ GIT_DIR=$(cat $GIT_DIR | awk '{print $2}')
+fi
+
+if [ ! -d "$GIT_DIR" ]; then
echo "This must be run from the root directory of the git working copy"
exit 1
fi
Please sign in to comment.
Something went wrong with that request. Please try again.