From e841a3b13293a629b093f6546f0e674e77090ee6 Mon Sep 17 00:00:00 2001
From: Chenxiong Qi <cqi@redhat.com>
Date: Sep 25 2017 12:21:16 +0000
Subject: [PATCH 1/2] Add .gitignore


Signed-off-by: Chenxiong Qi <cqi@redhat.com>

---

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d38c149
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+*.swp
+*~

From b2469e5ff8434e9c4958af8783442bd93e89cee7 Mon Sep 17 00:00:00 2001
From: Chenxiong Qi <cqi@redhat.com>
Date: Sep 25 2017 13:36:20 +0000
Subject: [PATCH 2/2] Enable namespaced package name


Signed-off-by: Chenxiong Qi <cqi@redhat.com>

---

diff --git a/bin/fedpkg-base b/bin/fedpkg-base
index 87d90e8..666df83 100755
--- a/bin/fedpkg-base
+++ b/bin/fedpkg-base
@@ -18,7 +18,17 @@
 # Abort on errors
 set -e
 
-pkgname=$(basename "$PWD")
+# Defaults to namespace rpms
+ns_pkgname="rpms/$(basename "$PWD")"
+# Then, if fedpkg-minimal runs inside a package repository, namespaced
+# package name is retrieved from remote url. That assumes there is only one
+# remote, the origin, in this repository. E.g.
+#     url = ssh://pkgs.fedoraproject.org/rpms/fedpkg.git
+# ns_pkgname is rpms/fedpkg
+if [ -r .git/config ]; then
+    ns_pkgname=$(grep " *url *= *" .git/config | rev | cut -d'/' -f1-2 | rev | cut -d'.' -f1)
+fi
+
 if [[ -s sources ]]; then
     # Read first word of first line. For old MD5 format it's the 32 character
     # hash. Otherwise let's assume the sources have the BSD format where lines
@@ -31,15 +41,15 @@ if [[ -s sources ]]; then
         # the same type, so we don't need to read it again for each line.
         while read -r _ filename _ hash; do
             # Remove parenthesis around tarball name
-	    filename=${filename#(}
-	    tarball=${filename%)}
-            curl -L -H Pragma: -o "./$tarball" -R -S --fail --retry 5 --max-time 15 "$baseurl/$pkgname/$tarball/$hashtype/$hash/$tarball"
+            filename=${filename#(}
+            tarball=${filename%)}
+            curl -L -H Pragma: -o "./$tarball" -R -S --fail --retry 5 --max-time 15 "$baseurl/$ns_pkgname/$tarball/$hashtype/$hash/$tarball"
         done < sources
         "${hashtype}sum" -c sources
     else
         # Ok, we're working with MD5.
         while read -r md5sum tarball; do
-            curl -L -H Pragma: -o "./$tarball" -R -S --fail --retry 5 --max-time 15 "$baseurl/$pkgname/$tarball/$md5sum/$tarball"
+            curl -L -H Pragma: -o "./$tarball" -R -S --fail --retry 5 --max-time 15 "$baseurl/$ns_pkgname/$tarball/$md5sum/$tarball"
         done < sources
         md5sum -c sources
     fi
diff --git a/bin/fedpkg-stg b/bin/fedpkg-stg
index 89933e1..b87eed9 100755
--- a/bin/fedpkg-stg
+++ b/bin/fedpkg-stg
@@ -18,4 +18,4 @@
 # Abort on errors
 set -e
 
-baseurl=https://src.stg.fedoraproject.org/repo/pkgs fedpkg-base $@
+baseurl=https://src.stg.fedoraproject.org/repo/rpkgs fedpkg-base $@
diff --git a/tests/run-tests.sh b/tests/run-tests.sh
index 69238eb..560686b 100755
--- a/tests/run-tests.sh
+++ b/tests/run-tests.sh
@@ -11,6 +11,7 @@ for t in $HERE/test_*; do
     output=$(mktemp)
     diff=$(mktemp)
     cd "$t"
+    test -e git && cp -r git/ .git/
     fedpkg sources >"$output"
     if diff -u expected "$output" >"$diff"; then
         printf "%-40s 0K\n" "$(basename "$t")"
@@ -21,6 +22,7 @@ for t in $HERE/test_*; do
         echo ""
         RET=$((RET + 1))
     fi
+    test -e .git && rm -rf .git
     cd "$HERE"
     rm -f "$output" "$diff"
 done
diff --git a/tests/test_md5_bsd/expected b/tests/test_md5_bsd/expected
index 792d67f..6a35ca4 100644
--- a/tests/test_md5_bsd/expected
+++ b/tests/test_md5_bsd/expected
@@ -1,2 +1,2 @@
-curl -L -H Pragma: -o ./github-linguist-4.8.18.gem -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/test_md5_bsd/github-linguist-4.8.18.gem/md5/192de5f33807d72e573c54f61892fc69/github-linguist-4.8.18.gem
+curl -L -H Pragma: -o ./github-linguist-4.8.18.gem -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/rpms/test_md5_bsd/github-linguist-4.8.18.gem/md5/192de5f33807d72e573c54f61892fc69/github-linguist-4.8.18.gem
 md5sum -c sources
diff --git a/tests/test_md5_old/expected b/tests/test_md5_old/expected
index 5ab54d1..41a7c11 100644
--- a/tests/test_md5_old/expected
+++ b/tests/test_md5_old/expected
@@ -1,2 +1,2 @@
-curl -L -H Pragma: -o ./entr-3.6.tar.gz -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/test_md5_old/entr-3.6.tar.gz/072eed7153296a8fae6ebdedefed9fd4/entr-3.6.tar.gz
+curl -L -H Pragma: -o ./entr-3.6.tar.gz -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/rpms/test_md5_old/entr-3.6.tar.gz/072eed7153296a8fae6ebdedefed9fd4/entr-3.6.tar.gz
 md5sum -c sources
diff --git a/tests/test_ns_pkgname/expected b/tests/test_ns_pkgname/expected
new file mode 100644
index 0000000..55b2515
--- /dev/null
+++ b/tests/test_ns_pkgname/expected
@@ -0,0 +1,2 @@
+curl -L -H Pragma: -o ./github-linguist-4.8.18.gem -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/container/ansible/github-linguist-4.8.18.gem/sha512/d556ffe0062bc2c745c46e94929eab18c79fd221ffc1dd0c0ea5868428bd130d7b15eec618e9c3940b50c27559923911135770792864f3330a606132dc8819c0/github-linguist-4.8.18.gem
+sha512sum -c sources
diff --git a/tests/test_ns_pkgname/git/config b/tests/test_ns_pkgname/git/config
new file mode 100644
index 0000000..270b713
--- /dev/null
+++ b/tests/test_ns_pkgname/git/config
@@ -0,0 +1,2 @@
+[remote "origin"]
+        url = ssh://cqi@pkgs.fedoraproject.org/container/ansible.git
diff --git a/tests/test_ns_pkgname/sources b/tests/test_ns_pkgname/sources
new file mode 100644
index 0000000..3b00ce4
--- /dev/null
+++ b/tests/test_ns_pkgname/sources
@@ -0,0 +1 @@
+SHA512 (github-linguist-4.8.18.gem) = d556ffe0062bc2c745c46e94929eab18c79fd221ffc1dd0c0ea5868428bd130d7b15eec618e9c3940b50c27559923911135770792864f3330a606132dc8819c0
diff --git a/tests/test_sha512_bsd/expected b/tests/test_sha512_bsd/expected
index fbbf4f6..2fcca00 100644
--- a/tests/test_sha512_bsd/expected
+++ b/tests/test_sha512_bsd/expected
@@ -1,2 +1,2 @@
-curl -L -H Pragma: -o ./github-linguist-4.8.18.gem -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/test_sha512_bsd/github-linguist-4.8.18.gem/sha512/d556ffe0062bc2c745c46e94929eab18c79fd221ffc1dd0c0ea5868428bd130d7b15eec618e9c3940b50c27559923911135770792864f3330a606132dc8819c0/github-linguist-4.8.18.gem
+curl -L -H Pragma: -o ./github-linguist-4.8.18.gem -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/rpms/test_sha512_bsd/github-linguist-4.8.18.gem/sha512/d556ffe0062bc2c745c46e94929eab18c79fd221ffc1dd0c0ea5868428bd130d7b15eec618e9c3940b50c27559923911135770792864f3330a606132dc8819c0/github-linguist-4.8.18.gem
 sha512sum -c sources

