From e7cde1164c2b2496abf5be3ffdc87da0d8aa3f22 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 17 May 2023 10:53:43 -0300 Subject: [PATCH] [Diff][Fixed] Assumption that all tags are in the trunk - As stated by @matthijskooijman in 91ffb04661c40102bfb856669039f0825ecc6883#r113724588 comment using --tags isn't necessary and includes *all* tags - The code also assumed nothing was added before the "tag: " label, but this isn't true if the HEAD is tagged. --- kibot/out_diff.py | 11 +++++---- tests/test_plot/test_misc.py | 48 ++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 5 deletions(-) diff --git a/kibot/out_diff.py b/kibot/out_diff.py index 0163f799..fa205d4d 100644 --- a/kibot/out_diff.py +++ b/kibot/out_diff.py @@ -254,21 +254,22 @@ class DiffOptions(BaseOptions): def process_tags(self, num): # Get a list of all tags ... and commits (how can I filter it?) logger.debug('Looking for git tags') - res = self.run_git(['rev-list', '--tags', '--format=format:%D']) + res = self.run_git(['rev-list', '--format=format:%D', 'HEAD']) if not res: return res res = res.split('\n') commit = '' skipped = 0 for v in res: - if v.startswith('tag: '): - tag = v.split(',')[0][4:] + try: + tag = v[v.index('tag: '):].split(',')[0][4:] logger.debugl(2, '- {}/{} tag: {} -> {}'.format(skipped, num, tag, commit)) if skipped == num: return commit skipped += 1 - elif v.startswith('commit '): - commit = v[7:] + except ValueError: + if v.startswith('commit '): + commit = v[7:] def solve_kibot_magic(self, name, tag): # The magic KIBOT_* diff --git a/tests/test_plot/test_misc.py b/tests/test_plot/test_misc.py index f0dc9192..589c524c 100644 --- a/tests/test_plot/test_misc.py +++ b/tests/test_plot/test_misc.py @@ -1479,6 +1479,54 @@ def test_diff_git_4(test_dir): ctx.clean_up(keep_project=True) +def test_diff_git_5(test_dir): + """ Difference between the two repo points, using tags """ + prj = 'light_control' + yaml = 'diff_git_5' + ctx = context.TestContext(test_dir, prj, yaml) + # Create a git repo + git_init(ctx) + # Copy the "old" file + pcb = prj+'.kicad_pcb' + file = ctx.get_out_path(pcb) + shutil.copy2(ctx.board_file, file) + shutil.copy2(ctx.board_file.replace('.kicad_pcb', context.KICAD_SCH_EXT), + file.replace('.kicad_pcb', context.KICAD_SCH_EXT)) + # Add it to the repo + ctx.run_command(['git', 'add', pcb], chdir_out=True) + ctx.run_command(['git', 'commit', '-m', 'Reference'], chdir_out=True) + # Tag it (this will be our target) + ctx.run_command(['git', 'tag', '-a', 't1', '-m', 't1'], chdir_out=True) + # Add an extra commit + dummy = ctx.get_out_path('dummy') + with open(dummy, 'wt') as f: + f.write('dummy\n') + ctx.run_command(['git', 'add', 'dummy'], chdir_out=True) + ctx.run_command(['git', 'commit', '-m', 'Dummy noise'], chdir_out=True) + # Add a noisy branch + ctx.run_command(['git', 'switch', '-c', 'a_branch'], chdir_out=True) + # Copy the "new" file + with open(file, 'wt') as f: + f.write('broken\n') + # Add it to the repo + ctx.run_command(['git', 'commit', '-a', '-m', 'New version'], chdir_out=True) + # Tag it (this shouldn't be a problem) + ctx.run_command(['git', 'tag', '-a', 't2', '-m', 't2'], chdir_out=True) + # Back to the master + ctx.run_command(['git', 'checkout', 'master'], chdir_out=True) + # Copy the "new" file + shutil.copy2(ctx.board_file.replace(prj, prj+'_diff'), file) + # Add it to the repo + ctx.run_command(['git', 'add', pcb], chdir_out=True) + ctx.run_command(['git', 'commit', '-m', 'New version'], chdir_out=True) + # Tag it (this shouldn't be a problem) + ctx.run_command(['git', 'tag', '-a', 't3', '-m', 't3'], chdir_out=True) + # Run the test + ctx.run(extra=['-b', file], no_board_file=True, extra_debug=True) + ctx.compare_pdf(prj+'-diff_pcb.pdf', off_y=OFFSET_Y, tol=DIFF_TOL) + ctx.clean_up(keep_project=True) + + @pytest.mark.slow @pytest.mark.eeschema def test_diff_file_sch_1(test_dir):