Skip to content

Commit

Permalink
Merge pull request #1570 from dmach/fix-mv
Browse files Browse the repository at this point in the history
Fix 'mv' command when renaming a file multiple times
  • Loading branch information
dmach committed May 27, 2024
2 parents dfff837 + e04651f commit e981645
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions behave/features/mv.feature
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,36 @@ Scenario: Run `osc mv <file> <new-name>` 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 <file> <new-name>` 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
4 changes: 4 additions & 0 deletions osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -9887,6 +9887,10 @@ def do_mv(self, subcmd, opts):
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',
Expand Down

0 comments on commit e981645

Please sign in to comment.