Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing subsubrepo test case #604

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

doak
Copy link

@doak doak commented Dec 13, 2023

If the outer subrepo bar is pushed before the inner subrepo doak, the latter will fail with fatal: this operation must be run in a work tree.

This PR add a test case respectively a show case.

Repository layout of test case

- foo                ("super" repo)
    L bar            (subrepo pushed first)
        L doak       (subrepo pushed second)

@doak
Copy link
Author

doak commented Dec 13, 2023

This is a show case in plain Bash:

#!/usr/bin/env bash

set -eu
trap '[ $? -eq 0 ] || echo FAILED' EXIT
set -o pipefail

BASEDIR=$(dirname -- "$0")

setupColors() {
    CRED="`tput setaf 1 2>/dev/null`" ||
    CRED=
    CGREEN="`tput setaf 2 2>/dev/null`" ||
    CGREEN=
    CYELLOW="`tput setaf 3 2>/dev/null`" ||
    CYELLOW=
    CBLUE="`tput setaf 4 2>/dev/null`" ||
    CBLUE=
    CRESET="`tput op 2>/dev/null`" ||
    CRESET=
}

prefixOutput() {
    local prefix=$1
    sed -uE "s/^/$prefix/"
}

check() {
    local line=${BASH_LINENO[0]}

    "$@" &&
    echo "${CGREEN}SUCCESS [$line]: ${@@Q}$CRESET" ||
    echo "${CRED}FAILURE [$line]: ${@@Q}$CRESET"
}

not() {
    ! "$@"
}

git() {
    case "$1" in
        #subrepo)
        #    command git subrepo --debug "${@:2}"
        #    ;;
        *)
            command git "$@"
            ;;
    esac
}

setupRepo() {
    cd "$BASEDIR"
    rm -rf "super" "project1" "project2"

    git init --bare "project1"
    git init --bare "project2"

    git init "super"
    cd "super"

    echo "super" >"file"
    git add "file"
    git commit -m "[1] super"

    mkdir "project1"
    echo "someContent" >"project1/p1"
    git add "project1"
    git commit -m "[1] project1"
    git subrepo init -r "../project1" "project1"

    mkdir -p "project1/ext/project2"
    echo "someContent" >"project1/ext/project2/p2"
    git add "project1"
    git commit -m "[1] project2"
    git subrepo init -r "../project2" "project1/ext/project2"
}


tc-pushSubRepos-OuterFirst() (
    setupRepo

    check git subrepo push "project1"
    check git subrepo push "project1/ext/project2"
)

tc-pushSubRepos-InnerFirst() (
    setupRepo


    check git subrepo push "project1/ext/project2"
    check git subrepo push "project1"
)


FILTER=${1:-.}

setupColors

TEST_CASES=($(
    grep -oP '^tc-\S*(?=\(\))' "$0" |
    grep -P "$FILTER" ||
    echo "No test cases found." >&2
))
for TC in "${TEST_CASES[@]}"; do
    {
        (
            set +e
            (
                set -e
                "$TC"
            )
            [ $? -eq 0 ] ||
            echo "${CRED}Test case aborted!$CRESET"
        ) |
        prefixOutput "$CBLUE[$TC]$CRESET "
        echo
    } 2>&1 1>&3 |
    prefixOutput "$CYELLOW[$TC]$CRESET "
done 3>&1 1>&2

@doak doak force-pushed the failing-subsubrepo-push branch from 9a37832 to 89c41b2 Compare December 16, 2023 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant