mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-26 07:18:31 +01:00
dvc: add 'dvc checkout'
Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import os
|
||||
from stat import ST_INO, ST_DEV
|
||||
|
||||
from dvc.command.base import CmdBase, DvcLock
|
||||
from dvc.logger import Logger
|
||||
from dvc.system import System
|
||||
|
||||
class CmdCheckout(CmdBase):
|
||||
def __init__(self, settings):
|
||||
super(CmdCheckout, self).__init__(settings)
|
||||
|
||||
@staticmethod
|
||||
def cache_ok(item):
|
||||
data = item.data.relative
|
||||
cache = item.cache.relative
|
||||
|
||||
if not os.path.isfile(data) or not os.path.isfile(cache):
|
||||
return False
|
||||
|
||||
data_st = os.stat(data)
|
||||
cache_st = os.stat(cache)
|
||||
|
||||
if (data_st[ST_INO], data_st[ST_DEV]) != (cache_st[ST_INO], cache_st[ST_DEV]):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def checkout(self, items):
|
||||
for item in items:
|
||||
if self.cache_ok(item):
|
||||
continue
|
||||
|
||||
if os.path.isfile(item.data.relative):
|
||||
os.remove(item.data.relative)
|
||||
|
||||
System.hardlink(item.cache.relative, item.data.relative)
|
||||
Logger.info('Checkout \'{}\''.format(item.data.relative))
|
||||
|
||||
def run(self):
|
||||
with DvcLock(self.is_locker, self.git):
|
||||
items = self.settings.path_factory.all_existing_data_items()
|
||||
self.checkout(items)
|
||||
return 0
|
||||
@@ -9,6 +9,7 @@ TESTS+=" test-import.sh"
|
||||
TESTS+=" test-sync.sh"
|
||||
TESTS+=" test-repro-code.sh"
|
||||
TESTS+=" test-merge.sh"
|
||||
TESTS+=" test-checkout.sh"
|
||||
|
||||
for t in $TESTS; do
|
||||
rm -rf $TEST_REPO
|
||||
|
||||
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
source common.sh
|
||||
|
||||
ITEM=data/xml/Badges.xml
|
||||
|
||||
dvc_create_repo
|
||||
|
||||
rm -f $ITEM
|
||||
dvc checkout
|
||||
dvc_check_files $ITEM
|
||||
dvc_pass
|
||||
Reference in New Issue
Block a user