]> git.scottworley.com Git - pinch/commitdiff
Reject duplicate channel names 1.2
authorScott Worley <scottworley@scottworley.com>
Tue, 19 May 2020 07:20:09 +0000 (00:20 -0700)
committerScott Worley <scottworley@scottworley.com>
Tue, 19 May 2020 07:27:09 +0000 (00:27 -0700)
pinch.py
tests/reject-duplicates.sh [new file with mode: 0755]

index b044faf34c0304dbdd20b55c84c9d27bd1b3832a..787555f1c9a3c06831d52139b673a3e7e4e8087f 100644 (file)
--- 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 (executable)
index 0000000..34e12c7
--- /dev/null
@@ -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" <<EOF
+[same]
+git_repo = file://$repo1
+git_ref = master
+EOF
+
+conf2="`mktemp`"
+cat > "$conf2" <<EOF
+[same]
+git_repo = file://$repo2
+git_ref = master
+EOF
+
+python3 ./pinch.py pin "$conf1"
+python3 ./pinch.py pin "$conf2"
+
+if python3 ./pinch.py update --dry-run "$conf1" "$conf2";then
+  echo "FAIL: Duplicate names should be rejected"
+  exit 1
+else
+  echo PASS
+fi
+
+rm -rf "$repo_dir1" "$repo_dir2" "$conf1" "$conf2"
+