Repository: packit/packit
Issue: propose-update does not find release tarball in dist-git with --dist-git-path

I'm currently trying to release the new [cockpit-podman 6](https://github.com/cockpit-project/cockpit-podman/releases/tag/6) with packit instead of cockpituous. This time, the upstream branch and release includes the [packit configuration](https://github.com/cockpit-project/cockpit-podman/blob/master/packit.yaml), so no --local-content.

I'm trying to run propose- update in a checkout of the upstream branch (not completely clean, as I built the release tarball in that before). I use `--dist-git-path` to work around issue #421. It seems to download the new release tarball from github just fine, but it seems to place it in the wrong directory:
```
$ PYTHONPATH=~/tmp/packit/ python3 -m packit.cli.packit_base propose-update --no-pr --dist-git-path=/tmp/cockpit-podman
Input is a directory: /home/martin/upstream/cockpit-podman
Using user-defined script for ActionName.post_upstream_clone: ['make cockpit-podman.spec']
INFO: Running 'anitya' versioneer
ERROR: Failed to determine latest upstream version!
Check that the package exists on https://release-monitoring.org.
Version in upstream registries is None.
Version in spec file is '6'.
Picking version found in spec file.
Checking out upstream version 6
Using 'master' dist-git branch
Archive cockpit-podman-6.tar.gz found in lookaside cache (skipping upload).
INFO: Downloading file from URL https://github.com/cockpit-project/cockpit-podman/releases/download/6/cockpit-podman-6.tar.gz
100%[=============================>]     1.59M  eta 00:00:00 
Downloaded archive: PosixPath('/tmp/tmpb8fbnoq4/cockpit-podman-6.tar.gz')
About to upload to lookaside cache
won't be doing kinit, no credentials provided
ERROR    Could not execute new_sources: Error checking for cockpit-podman-6.tar.gz at https://src.fedoraproject.org/repo/pkgs/upload.cgi

ERROR    Command ['fedpkg', 'new-sources', '/tmp/tmpb8fbnoq4/cockpit-podman-6.tar.gz'] failed
ERROR    Adding new sources failed:
ERROR    `fedpkg new-sources` failed for some reason. Either Fedora kerberos is invalid or there could be network outage.
ERROR    Command ['fedpkg', 'new-sources', '/tmp/tmpb8fbnoq4/cockpit-podman-6.tar.gz'] failed: Adding new sources failed:
```

And indeed /tmp/cockpit-podman/ is completely unaltered, no new tarball, changes, or commits. /tmp/tmpyyatb17l is gone.

This is packit master from today, 5c521f763.

Changed files:
tests/conftest.py, packit/config.py, packit/distgit.py, packit/cli/utils.py, tests/integration/test_update.py, tests/integration/test_create_update.py, tests/integration/test_build.py

diff --git a/packit/cli/utils.py b/packit/cli/utils.py
index cce878fe..22de60e3 100644
--- a/packit/cli/utils.py
+++ b/packit/cli/utils.py
@@ -110,7 +110,7 @@ def get_packit_api(
     )
 
     if dist_git_path:
-        package_config._downstream_project_url = dist_git_path
+        package_config.dist_git_clone_path = dist_git_path
     package_config.upstream_project_url = local_project.working_dir
 
     api = PackitAPI(
diff --git a/packit/config.py b/packit/config.py
index 1ccb04fc..f5054a5a 100644
--- a/packit/config.py
+++ b/packit/config.py
@@ -370,6 +370,8 @@ class PackageConfig(BaseConfig):
         self._downstream_package_name: Optional[str] = downstream_package_name
         self.dist_git_base_url: str = dist_git_base_url or PROD_DISTGIT_URL
         self._downstream_project_url: str = downstream_project_url
+        # path to a local git clone of the dist-git repo; None means to clone in a tmpdir
+        self.dist_git_clone_path: Optional[str] = None
         self.actions = actions or {}
         self.upstream_ref: Optional[str] = upstream_ref
         self.allowed_gpg_keys = allowed_gpg_keys
diff --git a/packit/distgit.py b/packit/distgit.py
index 65bec062..d87c492d 100644
--- a/packit/distgit.py
+++ b/packit/distgit.py
@@ -74,26 +74,35 @@ class DistGit(PackitRepositoryBase):
     def local_project(self):
         """ return an instance of LocalProject """
         if self._local_project is None:
-            tmpdir = tempfile.mkdtemp(prefix="packit-dist-git")
-            f = FedPKG(self.fas_user, tmpdir)
-            f.clone(
-                self.package_config.downstream_package_name,
-                tmpdir,
-                anonymous=not cccolutils.has_creds(),
+            pagure_service = PagureService(
+                token=self.pagure_user_token,
+                instance_url=self.package_config.dist_git_base_url,
+                read_only=self.config.dry_run,
             )
-
-            self._local_project = LocalProject(
-                working_dir=tmpdir,
-                git_url=self.package_config.dist_git_package_url,
-                namespace=self.package_config.dist_git_namespace,
-                repo_name=self.package_config.downstream_package_name,
-                git_service=PagureService(
-                    token=self.pagure_user_token,
-                    instance_url=self.package_config.dist_git_base_url,
-                    read_only=self.config.dry_run,
-                ),
-            )
-            self._local_project.working_dir_temporary = True
+            if self.package_config.dist_git_clone_path:
+                self._local_project = LocalProject(
+                    working_dir=self.package_config.dist_git_clone_path,
+                    git_url=self.package_config.dist_git_package_url,
+                    namespace=self.package_config.dist_git_namespace,
+                    repo_name=self.package_config.downstream_package_name,
+                    git_service=pagure_service,
+                )
+            else:
+                tmpdir = tempfile.mkdtemp(prefix="packit-dist-git")
+                f = FedPKG(self.fas_user, tmpdir)
+                f.clone(
+                    self.package_config.downstream_package_name,
+                    tmpdir,
+                    anonymous=not cccolutils.has_creds(),
+                )
+                self._local_project = LocalProject(
+                    working_dir=tmpdir,
+                    git_url=self.package_config.dist_git_package_url,
+                    namespace=self.package_config.dist_git_namespace,
+                    repo_name=self.package_config.downstream_package_name,
+                    git_service=pagure_service,
+                )
+                self._local_project.working_dir_temporary = True
         return self._local_project
 
     @property
diff --git a/tests/conftest.py b/tests/conftest.py
index bccd1288..5744a132 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -75,7 +75,7 @@ def mock_downstream_remote_functionality(downstream_n_distgit):
     mock_spec_download_remote_s(d)
 
     pc = get_local_package_config(str(u))
-    pc._downstream_project_url = str(d)
+    pc.dist_git_clone_path = str(d)
     pc.upstream_project_url = str(u)
     return u, d
 
@@ -162,7 +162,7 @@ def mock_remote_functionality(distgit: Path, upstream: Path):
 
     flexmock(FedPKG, init_ticket=lambda x=None: None, new_sources=mocked_new_sources)
     pc = get_local_package_config(str(upstream))
-    pc._downstream_project_url = str(distgit)
+    pc.dist_git_clone_path = str(distgit)
     pc.upstream_project_url = str(upstream)
     return upstream, distgit
 
@@ -250,7 +250,7 @@ def upstream_instance(upstream_n_distgit, tmpdir):
 
         pc = get_local_package_config(str(u))
         pc.upstream_project_url = str(u)
-        pc._downstream_project_url = str(d)
+        pc.dist_git_clone_path = str(d)
         lp = LocalProject(working_dir=str(u))
 
         ups = Upstream(c, pc, lp)
@@ -271,7 +271,7 @@ def distgit_instance(upstream_n_distgit, mock_remote_functionality_upstream):
     u, d = upstream_n_distgit
     c = get_test_config()
     pc = get_local_package_config(str(u))
-    pc._downstream_project_url = str(d)
+    pc.dist_git_clone_path = str(d)
     pc.upstream_project_url = str(u)
     dg = DistGit(c, pc)
     return d, dg
@@ -303,7 +303,7 @@ def api_instance_source_git(sourcegit_n_distgit):
         c = get_test_config()
         pc = get_local_package_config(str(sourcegit))
         pc.upstream_project_url = str(sourcegit)
-        pc._downstream_project_url = str(distgit)
+        pc.dist_git_clone_path = str(distgit)
         up_lp = LocalProject(working_dir=str(sourcegit))
         api = PackitAPI(c, pc, up_lp)
         return api
diff --git a/tests/integration/test_build.py b/tests/integration/test_build.py
index 4baef4f1..e3b2211c 100644
--- a/tests/integration/test_build.py
+++ b/tests/integration/test_build.py
@@ -38,7 +38,7 @@ def test_basic_build(upstream_n_distgit, mock_remote_functionality_upstream):
 
         pc = get_local_package_config(str(u))
         pc.upstream_project_url = str(u)
-        pc._downstream_project_url = str(d)
+        pc.dist_git_clone_path = str(d)
         up_lp = LocalProject(working_dir=u)
 
         api = PackitAPI(c, pc, up_lp)
diff --git a/tests/integration/test_create_update.py b/tests/integration/test_create_update.py
index 8f0e9719..539b6f1b 100644
--- a/tests/integration/test_create_update.py
+++ b/tests/integration/test_create_update.py
@@ -298,7 +298,7 @@ def test_basic_bodhi_update(
 
         pc = get_local_package_config(str(u))
         pc.upstream_project_url = str(u)
-        pc._downstream_project_url = str(d)
+        pc.dist_git_clone_path = str(d)
         up_lp = LocalProject(working_dir=u)
 
         api = PackitAPI(c, pc, up_lp)
diff --git a/tests/integration/test_update.py b/tests/integration/test_update.py
index c600d69a..f5233357 100644
--- a/tests/integration/test_update.py
+++ b/tests/integration/test_update.py
@@ -64,7 +64,7 @@ def test_basic_local_update(upstream_n_distgit, mock_remote_functionality_upstre
 
         pc = get_local_package_config(str(u))
         pc.upstream_project_url = str(u)
-        pc._downstream_project_url = str(d)
+        pc.dist_git_clone_path = str(d)
         up_lp = LocalProject(working_dir=str(u))
         api = PackitAPI(c, pc, up_lp)
         api.sync_release("master", "0.1.0")
@@ -90,7 +90,7 @@ def test_basic_local_update_direct_push(
 
         pc = get_local_package_config(str(upstream))
         pc.upstream_project_url = str(upstream)
-        pc._downstream_project_url = str(distgit)
+        pc.dist_git_clone_path = str(distgit)
         up_lp = LocalProject(working_dir=str(upstream))
         api = PackitAPI(c, pc, up_lp)
         api.sync_release("master", "0.1.0", create_pr=False)
@@ -116,7 +116,7 @@ def test_basic_local_update_from_downstream(
         c = get_test_config()
         pc = get_local_package_config(str(u))
         pc.upstream_project_url = str(u)
-        pc._downstream_project_url = str(d)
+        pc.dist_git_clone_path = str(d)
         up_lp = LocalProject(working_dir=str(u))
         api = PackitAPI(c, pc, up_lp)
         api.sync_from_downstream("master", "master", True)