[PATCH 1/2] repos: leave url unset if not specified in configuration

10 views
Skip to first unread message

Daniel Wagenknecht

unread,
Oct 15, 2021, 5:30:52 AM10/15/21
to kas-...@googlegroups.com
For repositories that don't have a url set in the project configuration
the url was set to the path. This doesn't align with the documentation
for the `for-all-repos` plugin:
> KAS_REPO_URL: The URL from which this repository was cloned, or an
> empty string if no remote URL was given in the config file.

Align the implementation to the documentation.

This way performing actions with the `for-all-repos` plugin only on
version controlled repositories can be done with a check for
KAS_REPO_URL being non-empty.

Signed-off-by: Daniel Wagenknecht <dwagen...@emlix.com>
---
kas/repos.py | 1 -
1 file changed, 1 deletion(-)

diff --git a/kas/repos.py b/kas/repos.py
index 1eb2e5c..59827cd 100644
--- a/kas/repos.py
+++ b/kas/repos.py
@@ -127,7 +127,6 @@ class Repo:

if url is None:
# No version control operation on repository
- url = path
disable_operations = True

if typ == 'git':
--
2.25.1

Daniel Wagenknecht

unread,
Oct 15, 2021, 5:30:57 AM10/15/21
to kas-...@googlegroups.com
The `this` repo is skipped in the test for the `for-all-repos` command.
Adapt to checking for KAS_REPO_URL being empty instead of comparing the
KAS_REPO_NAME. This way the test will fail if the implementation
diverges from the documentation:
> KAS_REPO_URL: The URL from which this repository was cloned, or an
> empty string if no remote URL was given in the config file.

Signed-off-by: Daniel Wagenknecht <dwagen...@emlix.com>
---
tests/test_commands.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tests/test_commands.py b/tests/test_commands.py
index 6195bb1..2d615b3 100644
--- a/tests/test_commands.py
+++ b/tests/test_commands.py
@@ -32,7 +32,7 @@ def test_for_all_repos(changedir, tmpdir):
shutil.copytree('tests/test_commands', tdir)
os.chdir(tdir)
kas.kas(['for-all-repos', 'test.yml',
- '''if [ "${KAS_REPO_NAME}" != "this" ]; then git rev-parse HEAD \
+ '''if [ -n "${KAS_REPO_URL}" ]; then git rev-parse HEAD \
>> %s/ref_${KAS_REPO_NAME}; fi''' % (tdir)])

with open('ref_kas_1.0', 'r') as f:
--
2.25.1

Jan Kiszka

unread,
Oct 15, 2021, 9:24:31 AM10/15/21
to Daniel Wagenknecht, kas-...@googlegroups.com
This looks broken, at least for anything else but the for-all-repos plugin.

If you look at the Repo class, you see a lot of references to self.repo,
and none of them taking care of repo == None. Even setting url to an
empty string above may bring regressions. We need to consider all details.

Jan

--
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux

Jan Kiszka

unread,
Oct 15, 2021, 9:30:02 AM10/15/21
to Daniel Wagenknecht, kas-...@googlegroups.com
Does this work?

diff --git a/kas/plugins/for_all_repos.py b/kas/plugins/for_all_repos.py
index 7ec977c..20824f3 100644
--- a/kas/plugins/for_all_repos.py
+++ b/kas/plugins/for_all_repos.py
@@ -98,7 +98,7 @@ class ForAllReposCommand(Command):
**ctx.environ,
'KAS_REPO_NAME': repo.name,
'KAS_REPO_PATH': repo.path,
- 'KAS_REPO_URL': repo.url or '',
+ 'KAS_REPO_URL': repo.url if repo.url != repo.path else '',
'KAS_REPO_REFSPEC': repo.refspec or '',
}
logging.info('%s$ %s', repo.path, self.command)
Reply all
Reply to author
Forward
0 new messages