-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve template url generations (#3108)
1. Check that a git repository is defined and get the basic facts 2. Try to get a fully-qualified reference from branch (rev-parse --symbolic-full-name), tag (describe --tags), or the first entry of for-each-ref 3. Set fmf_id.ref to a short name if possible. Depends on if we are a branch or tag. 4. Get all remaining facts from the fully-qualified reference and for-each-ref Signed-off-by: Cristian Le <[email protected]> Signed-off-by: Cristian Le <[email protected]> Co-authored-by: Petr Šplíchal <[email protected]>
- Loading branch information
Showing
8 changed files
with
197 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,7 @@ def local_git_repo(tmppath: Path) -> Path: | |
origin = tmppath / 'origin' | ||
origin.mkdir() | ||
|
||
run(Command('git', 'init'), cwd=origin) | ||
run(Command('git', 'init', '-b', 'main'), cwd=origin) | ||
run( | ||
Command('git', 'config', '--local', 'user.email', '[email protected]'), | ||
cwd=origin) | ||
|
@@ -920,6 +920,45 @@ def test_not_pushed(cls, origin_and_local_git_repo: tuple[Path, Path], root_logg | |
False, 'Not pushed changes in .fmf/version main.fmf') | ||
|
||
|
||
@pytest.mark.parametrize("git_ref", | ||
["tag", "branch", "merge", "commit"]) | ||
def test_fmf_id(local_git_repo, root_logger, git_ref): | ||
run(Command('git', 'checkout', '-b', 'other_branch'), cwd=local_git_repo) | ||
# Initialize tmt tree with a test | ||
tmt.Tree.init(logger=root_logger, path=local_git_repo, template="empty", force=False) | ||
with (local_git_repo / "test.fmf").open("w") as f: | ||
f.write('test: echo') | ||
run(Command('git', 'add', '-A'), cwd=local_git_repo) | ||
run(Command('git', 'commit', '-m', 'Initialized tmt tree'), cwd=local_git_repo) | ||
commit_hash = run(Command('git', 'rev-parse', 'HEAD'), cwd=local_git_repo).stdout.strip() | ||
|
||
if git_ref == "tag": | ||
run(Command('git', 'tag', 'some_tag'), cwd=local_git_repo) | ||
run(Command('git', 'checkout', 'some_tag'), cwd=local_git_repo) | ||
if git_ref == "commit": | ||
# Create an empty commit and checkout the previous commit | ||
run(Command('git', 'commit', '--allow-empty', '-m', | ||
'Random other commit'), cwd=local_git_repo) | ||
run(Command('git', 'checkout', 'HEAD^'), cwd=local_git_repo) | ||
if git_ref == "merge": | ||
run(Command('git', 'checkout', '--detach', 'main'), cwd=local_git_repo) | ||
run(Command('git', 'merge', 'other_branch'), cwd=local_git_repo) | ||
commit_hash = run(Command('git', 'rev-parse', 'HEAD'), | ||
cwd=local_git_repo).stdout.strip() | ||
|
||
fmf_id = tmt.utils.fmf_id(name="/test", fmf_root=local_git_repo, logger=root_logger) | ||
assert fmf_id.git_root == local_git_repo | ||
assert fmf_id.ref is not None | ||
if git_ref == "tag": | ||
assert fmf_id.ref == "some_tag" | ||
if git_ref == "branch": | ||
assert fmf_id.ref == "other_branch" | ||
if git_ref == "merge": | ||
assert fmf_id.ref == commit_hash | ||
if git_ref == "commit": | ||
assert fmf_id.ref == commit_hash | ||
|
||
|
||
class TestGitAdd: | ||
@classmethod | ||
def test_not_in_repository( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters