From ab7ebb2f956159d846cf9eb18d78130bd5821aaf Mon Sep 17 00:00:00 2001 From: Scott Worley Date: Tue, 19 May 2020 00:20:09 -0700 Subject: [PATCH 1/1] Reject duplicate channel names --- pinch.py | 4 ++++ tests/reject-duplicates.sh | 48 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 tests/reject-duplicates.sh diff --git a/pinch.py b/pinch.py index b044faf..787555f 100644 --- a/pinch.py +++ b/pinch.py @@ -514,6 +514,8 @@ def update(args: argparse.Namespace) -> None: ensure_git_rev_available(v, channel) tarball = git_get_tarball(v, channel) + if section in exprs: + raise Exception('Duplicate channel "%s"' % section) exprs[section] = ( 'f: f { name = "%s"; channelName = "%%s"; src = builtins.storePath "%s"; }' % (config[section]['release_name'], tarball)) @@ -521,6 +523,8 @@ def update(args: argparse.Namespace) -> None: for config in configs: for section in config.sections(): if 'alias_of' in config[section]: + if section in exprs: + raise Exception('Duplicate channel "%s"' % section) exprs[section] = exprs[str(config[section]['alias_of'])] command = [ diff --git a/tests/reject-duplicates.sh b/tests/reject-duplicates.sh new file mode 100755 index 0000000..34e12c7 --- /dev/null +++ b/tests/reject-duplicates.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +repo_dir1="`mktemp -d`" +repo1="$repo_dir1/repo" +git init "$repo1" +( + cd "$repo1" + echo Contents > test-file + git add test-file + git commit -m 'Commit message' +) + +repo_dir2="`mktemp -d`" +repo2="$repo_dir2/repo" +git init "$repo2" +( + cd "$repo2" + echo Contents > test-file + git add test-file + git commit -m 'Commit message' +) + +conf1="`mktemp`" +cat > "$conf1" < "$conf2" <