From 0513a8464c6075a5aa5082f3671211474dfcd301 Mon Sep 17 00:00:00 2001 From: clime Date: Jul 26 2017 11:01:08 +0000 Subject: [dist-git] fix #106 Renaming a spec file in a newer version causes the build to fail --- diff --git a/beaker-tests/Regression/dist-git/tests/batch1/import-tasks.json b/beaker-tests/Regression/dist-git/tests/batch1/import-tasks.json index a8aca49..015d99f 100644 --- a/beaker-tests/Regression/dist-git/tests/batch1/import-tasks.json +++ b/beaker-tests/Regression/dist-git/tests/batch1/import-tasks.json @@ -192,7 +192,7 @@ "branches": ["master"], "project": "example", - "source_json": "{\"tito_test\": true, \"git_dir\": \"Webapp/ghc-tagstream-conduit\", \"git_url\": \"https://gitlab.com/qulogic-rpms/git-annex.git\", \"git_branch\": \"master\"}", + "source_json": "{\"tito_test\": true, \"git_dir\": \"Webapp/ghc-yesod\", \"git_url\": \"https://gitlab.com/qulogic-rpms/git-annex.git\", \"git_branch\": \"master\"}", "source_type": 3, "task_id": "18", "user": "clime" @@ -236,7 +236,7 @@ "branches": ["master"], "project": "example", - "source_json": "{\"tito_test\": false, \"git_dir\": \"Webapp/ghc-tagstream-conduit\", \"git_url\": \"https://gitlab.com/qulogic-rpms/git-annex.git\", \"git_branch\": \"master\"}", + "source_json": "{\"tito_test\": false, \"git_dir\": \"Webapp/ghc-yesod\", \"git_url\": \"https://gitlab.com/qulogic-rpms/git-annex.git\", \"git_branch\": \"master\"}", "source_type": 3, "task_id": "22", "user": "clime" diff --git a/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/import-tasks.json b/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/import-tasks.json new file mode 100644 index 0000000..097e991 --- /dev/null +++ b/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/import-tasks.json @@ -0,0 +1,24 @@ +[ +{ + "_description": "srpm containing specfile named example.spec", + "_expected_outcome": "success", + + "branches": ["master"], + "project": "example", + "source_json": "{\"url\": \"http://localhost:5000/static/example.src.rpm\"}", + "source_type": 1, + "task_id": "1", + "user": "clime" +}, +{ + "_description": "srpm containing specfile named foo.spec", + "_expected_outcome": "success", + + "branches": ["master"], + "project": "example", + "source_json": "{\"url\": \"http://localhost:5000/static/foo.src.rpm\"}", + "source_type": 1, + "task_id": "2", + "user": "clime" +} +] diff --git a/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/run.sh b/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/run.sh new file mode 100755 index 0000000..446b97b --- /dev/null +++ b/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/run.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +. /usr/bin/rhts-environment.sh || exit 1 +. /usr/share/beakerlib/beakerlib.sh || exit 1 + +export TESTPATH="$( builtin cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +export IN=$TESTPATH/import-tasks.json +export OUT=$TESTPATH/import-results.out.json +export MYTMPDIR=$TESTPATH/tmp # MY- prefix because otherwise there is a conflict with mkstemp + +rlJournalStart + rlPhaseStartTest TestTemplate + # input crunching + rlRun "/usr/share/copr/mocks/frontend/app.py $TESTPATH $TESTPATH/static" 0 + + # basic outcomes comparison + rlRun "jq -e -n --argfile a $IN --argfile b $OUT\ + '(\$a | sort_by(.task_id) | map({task_id: .task_id, status: (if (._expected_outcome == \"success\") then 1 else 0 end)})) ==\ + (\$b | sort_by(.task_id) | map({task_id: .task_id, status: (if (.git_hash) then 1 else 0 end)}))'" 0 "Compare expected and actual import outcomes (success/fail)." + + mkdir $MYTMPDIR && cd $MYTMPDIR + rlRun "git clone http://localhost/cgit/clime/example/example.git" 0 + rlRun "cd example" 0 + ls *.spec + rlAssertEquals "There is only one spec present in master." "`ls *.spec | wc -l`" "1" + cd $TESTPATH && rm -rf $MYTMPDIR + rlPhaseEnd +rlJournalEnd &> /dev/null diff --git a/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/static/example.src.rpm b/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/static/example.src.rpm new file mode 100644 index 0000000..fae0676 Binary files /dev/null and b/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/static/example.src.rpm differ diff --git a/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/static/foo.src.rpm b/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/static/foo.src.rpm new file mode 100644 index 0000000..262425f Binary files /dev/null and b/beaker-tests/Regression/dist-git/tests/old_files_are_deleted/static/foo.src.rpm differ diff --git a/dist-git/dist_git/package_import.py b/dist-git/dist_git/package_import.py index 8086131..df0a475 100644 --- a/dist-git/dist_git/package_import.py +++ b/dist-git/dist_git/package_import.py @@ -138,6 +138,22 @@ def setup_git_repo(reponame, branches): raise PackageImportException(e.output) +def cleanup_repo(repo_path): + """ + Remove all files from the given repository + except special ones. + + :param str repo_path: path to the repository + """ + to_remove = [] + for f in os.listdir(repo_path): + if f not in ['.git', '.gitignore', 'sources']: + to_remove.append(f) + if to_remove: + helpers.run_cmd( + ['git', 'rm', '-r'] + to_remove) + + @helpers.single_run(import_lock) def import_package(opts, namespace, branches, package_content): """ @@ -212,6 +228,8 @@ def import_package(opts, namespace, branches, package_content): try: if not branch_commits: + cleanup_repo('.') + log.debug("add package content") add_to_index = [] shutil.copy(package_content.spec_path, repo_dir)