[PATCH/RFC 06/20] rebase: collect check for existing rebase
Put the code that checks for rebase in progress in one place.
Signed-off-by: Martin von Zweigbergk <martin.von.zweigbergk@gmail.com>
---
git-rebase.sh | 56 +++++++++++++++++++++++++-------------------------------
1 files changed, 25 insertions(+), 31 deletions(-)
diff --git a/git-rebase.sh b/git-rebase.sh
index 52e1c6e..2358e2f 100755
--- a/git-rebase.sh
+++ b/git-rebase.sh
@@ -318,6 +318,31 @@ test $# -gt 2 && usage
if test -n "$action"
then
test -d "$merge_dir" -o -d "$apply_dir" || die "No rebase in progress?"
+else
+ # Make sure we do not have $apply_dir or $merge_dir
+ if test -z "$do_merge"
+ then
+ if mkdir "$apply_dir" 2>/dev/null
+ then
+ rmdir "$apply_dir"
+ else
+ echo >&2 '
+It seems that I cannot create a rebase-apply directory, and
+I wonder if you are in the middle of patch application or another
+rebase. If that is not the case, please
+ rm -fr '"$apply_dir"'
+and run me again. I am stopping in case you still have something
+valuable there.'
+ exit 1
+ fi
+ else
+ if test -d "$merge_dir"
+ then
+ die "previous rebase directory $merge_dir still exists." \
+ 'Try git rebase (--continue | --abort | --skip)'
+ fi
+ fi
+ test $# -eq 0 && test -z "$rebase_root" && usage
fi
case "$action" in
@@ -378,37 +403,6 @@ abort)
;;
esac
-if test $# -eq 0 && test -z "$rebase_root"
-then
- test -d "$merge_dir" -o -d "$apply_dir" || usage
- test -d "$merge_dir" -o -f "$apply_dir"/rebasing &&
- die 'A rebase is in progress, try --continue, --skip or --abort.'
-fi
-
-# Make sure we do not have $apply_dir or $merge_dir
-if test -z "$do_merge"
-then
- if mkdir "$apply_dir" 2>/dev/null
- then
- rmdir "$apply_dir"
- else
- echo >&2 '
-It seems that I cannot create a rebase-apply directory, and
-I wonder if you are in the middle of patch application or another
-rebase. If that is not the case, please
- rm -fr '"$apply_dir"'
-and run me again. I am stopping in case you still have something
-valuable there.'
- exit 1
- fi
-else
- if test -d "$merge_dir"
- then
- die "previous rebase directory $merge_dir still exists." \
- 'Try git rebase (--continue | --abort | --skip)'
- fi
-fi
-
require_clean_work_tree "rebase" "Please commit or stash them."
if test -z "$rebase_root"
--
1.7.3.2.864.gbbb96