From e04651fa82b1ab76a93b4e24c137d354a9d1bc82 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Mon, 27 May 2024 07:52:35 +0200 Subject: [PATCH] Fix 'mv' command when renaming a file multiple times --- behave/features/mv.feature | 33 +++++++++++++++++++++++++++++++++ osc/commandline.py | 4 ++++ 2 files changed, 37 insertions(+) diff --git a/behave/features/mv.feature b/behave/features/mv.feature index d6deecb8..36dd20dc 100644 --- a/behave/features/mv.feature +++ b/behave/features/mv.feature @@ -19,3 +19,36 @@ Scenario: Run `osc mv ` in a package checkout """ And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes" does not exist And file "{context.osc.temp}/test:factory/test-pkgA/new-name.changes" exists + + +Scenario: Run `osc mv ` several times + When I execute osc with args "mv test-pkgA.changes test-pkgA.changes-1" + Then the exit code is 0 + And I execute osc with args "status" + And stdout is + """ + D test-pkgA.changes + A test-pkgA.changes-1 + """ + And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes" does not exist + And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes-1" exists + When I execute osc with args "mv test-pkgA.changes-1 test-pkgA.changes-2" + Then the exit code is 0 + And I execute osc with args "status" + And stdout is + """ + D test-pkgA.changes + A test-pkgA.changes-2 + """ + And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes" does not exist + And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes-2" exists + When I execute osc with args "mv test-pkgA.changes-2 test-pkgA.changes-3" + Then the exit code is 0 + And I execute osc with args "status" + And stdout is + """ + D test-pkgA.changes + A test-pkgA.changes-3 + """ + And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes" does not exist + And file "{context.osc.temp}/test:factory/test-pkgA/test-pkgA.changes-3" exists diff --git a/osc/commandline.py b/osc/commandline.py index 09384174..6412bfcc 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -9887,6 +9887,10 @@ Please submit there instead, or use --nodevelproject to force direct submission. except oscerr.PackageFileConflict: # file is already tracked pass + + # instantiate src_pkg *again* to load fresh state from .osc that was written on deleting a file in tgt_pkg + # it would be way better to use a single Package instance where possible + src_pkg = Package(source) src_pkg.delete_file(os.path.basename(source), force=opts.force) @cmdln.option('-d', '--delete', action='store_true',