allow using --branch with existing branches if it makes sense
This commit is contained in:
parent
2da0969a79
commit
0a562948ae
@ -161,6 +161,20 @@ rev_exists()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rev_is_descendant_of_branch()
|
||||||
|
{
|
||||||
|
newrev="$1"
|
||||||
|
branch="$2"
|
||||||
|
branch_hash=$(git rev-parse $branch)
|
||||||
|
match=$(git rev-list $newrev | grep $branch_hash)
|
||||||
|
|
||||||
|
if [ -n "$match" ]; then
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# if a commit doesn't have a parent, this might not work. But we only want
|
# if a commit doesn't have a parent, this might not work. But we only want
|
||||||
# to remove the parent from the rev-list, and since it doesn't exist, it won't
|
# to remove the parent from the rev-list, and since it doesn't exist, it won't
|
||||||
# be there anyway, so do nothing in that case.
|
# be there anyway, so do nothing in that case.
|
||||||
@ -476,10 +490,6 @@ cmd_add()
|
|||||||
|
|
||||||
cmd_split()
|
cmd_split()
|
||||||
{
|
{
|
||||||
if [ -n "$branch" ] && rev_exists "refs/heads/$branch"; then
|
|
||||||
die "Branch '$branch' already exists."
|
|
||||||
fi
|
|
||||||
|
|
||||||
debug "Splitting $dir..."
|
debug "Splitting $dir..."
|
||||||
cache_setup || exit $?
|
cache_setup || exit $?
|
||||||
|
|
||||||
@ -510,7 +520,8 @@ cmd_split()
|
|||||||
eval "$grl" |
|
eval "$grl" |
|
||||||
while read rev parents; do
|
while read rev parents; do
|
||||||
revcount=$(($revcount + 1))
|
revcount=$(($revcount + 1))
|
||||||
say -n "$revcount/$revmax ($createcount)
"
|
say -n "$revcount/$revmax ($createcount)
|
||||||
|
"
|
||||||
debug "Processing commit: $rev"
|
debug "Processing commit: $rev"
|
||||||
exists=$(cache_get $rev)
|
exists=$(cache_get $rev)
|
||||||
if [ -n "$exists" ]; then
|
if [ -n "$exists" ]; then
|
||||||
@ -548,9 +559,16 @@ cmd_split()
|
|||||||
$latest_new >&2 || exit $?
|
$latest_new >&2 || exit $?
|
||||||
fi
|
fi
|
||||||
if [ -n "$branch" ]; then
|
if [ -n "$branch" ]; then
|
||||||
git update-ref -m 'subtree split' "refs/heads/$branch" \
|
if rev_exists "refs/heads/$branch"; then
|
||||||
$latest_new "" || exit $?
|
if ! rev_is_descendant_of_branch $latest_new $branch; then
|
||||||
say "Created branch '$branch'"
|
die "Branch '$branch' is not an ancestor of commit '$latest_new'."
|
||||||
|
fi
|
||||||
|
action='Updated'
|
||||||
|
else
|
||||||
|
action='Created'
|
||||||
|
fi
|
||||||
|
git update-ref -m 'subtree split' "refs/heads/$branch" $latest_new || exit $?
|
||||||
|
say "$action branch '$branch'"
|
||||||
fi
|
fi
|
||||||
echo $latest_new
|
echo $latest_new
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
Reference in New Issue
Block a user