${PRINT_USAGE:-:} <<EOF
    rm <module>       Removes the specified module from the current environment. Errors if
                        changes are present and --force is not used.
EOF

# current group modules with uncommitted changes
uncommitted_changes() {
    debug "$FUNCNAME"
    gita ll|grep '+\|*'|cut -f1 -d' '
}

# remove stash save without applying
drop_stash() {
    debug "$FUNCNAME $1 $2"
    local mod=$1
    local branch=$2
    pushd $workspace/$mod || error "No module for $mod"
    local stashid=$(git stash list | grep $stashtag | grep "n $branch:"| cut -f1 -d:)
    git stash drop >/dev/null
    popd
}

# rm a module from a context
rm_mod() {
    debug "$FUNCNAME $1 $2"
    local mod=$1
    local branch=$2
    [[ -z "$mod" ]] && error "no mod passed to rm_mod"
    [[ -z "$branch" ]] && error "no branch passed to rm_mod"
    debug "$FUNCNAME uc: $(uncommitted_changes|grep '^$mod$')"
    if uncommitted_changes|grep "^$mod$" ; then
        debug "$FUNCNAME uncommitted_changes $mod"
        [[ -z force ]] && error "Unstaged changes present in $mod, fix or use --force"
        drop_stash $mod $branch
    fi
    pushd $workspace/$mod || error "unable to cd to mod dir: $workspace/$mod"
    gita group rmrepo -n $branch $mod
    co_branch $mod 'DEFAULT'
    git branch -D $branch
    popd
}

command_rm() {
    [[ -z $context ]] && error "Create an environment before tryig to remove mods"
    for m in $args ; do
        rm_mod $m $context
    done
}
return 0
