Prevent checkout in existing sessions.
This commit is contained in:
@@ -110,9 +110,9 @@ class bam_config:
|
||||
|
||||
def find_sessiondir(cwd=None, abort=False):
|
||||
"""
|
||||
from: my_bam/my_session/some/subdir
|
||||
to: my_bam/my_session
|
||||
where: my_bam/.bam/ (is the basedir)
|
||||
from: my_project/my_session/some/subdir
|
||||
to: my_project/my_session
|
||||
where: my_project/.bam/ (is the basedir)
|
||||
"""
|
||||
session_rootdir = bam_config.find_basedir(
|
||||
cwd=cwd,
|
||||
@@ -355,7 +355,6 @@ class bam_commands:
|
||||
|
||||
@staticmethod
|
||||
def checkout(path, output_dir=None, session_rootdir_partial=None):
|
||||
import requests
|
||||
|
||||
cfg = bam_config.load(abort=True)
|
||||
|
||||
@@ -367,20 +366,22 @@ class bam_commands:
|
||||
if os.sep in output_dir.rstrip(os.sep):
|
||||
# are we a subdirectory?
|
||||
# (we know this exists, since we have config already)
|
||||
rootdir = bam_config.find_rootdir(abort=True)
|
||||
if ".." in os.path.relpath(output_dir, rootdir).split(os.sep):
|
||||
fatal("Output %r is outside the project path %r" % (output_dir, rootdir))
|
||||
del rootdir
|
||||
project_rootdir = bam_config.find_rootdir(abort=True)
|
||||
if ".." in os.path.relpath(output_dir, project_rootdir).split(os.sep):
|
||||
fatal("Output %r is outside the project path %r" % (output_dir, project_rootdir))
|
||||
del project_rootdir
|
||||
dst_dir = output_dir
|
||||
del output_dir
|
||||
|
||||
if session_rootdir_partial:
|
||||
pass
|
||||
if bam_config.find_sessiondir(cwd=dst_dir):
|
||||
fatal("Can't checkout in existing session. Use update.")
|
||||
|
||||
payload = {
|
||||
"filepath": path,
|
||||
"command": "checkout",
|
||||
}
|
||||
|
||||
import requests
|
||||
r = requests.get(
|
||||
bam_session.request_url("file"),
|
||||
params=payload,
|
||||
|
@@ -833,6 +833,21 @@ class BamCheckoutTest(BamSessionTestCase):
|
||||
file_data_test = file_quick_read(os.path.join(session_path, file_name))
|
||||
self.assertEqual(file_data, file_data_test)
|
||||
|
||||
def test_checkout_in_existing_session(self):
|
||||
session_name = "mysession"
|
||||
file_name = "other_file.txt"
|
||||
file_data = b"yo world!\n"
|
||||
|
||||
proj_path, session_path = self.init_session(session_name)
|
||||
|
||||
# now do a real commit
|
||||
file_quick_write(session_path, file_name, file_data)
|
||||
stdout, stderr = bam_run(["commit", "-m", "test message"], session_path)
|
||||
self.assertEqual("", stderr)
|
||||
|
||||
# checkout inside of the existing session, should raise exception
|
||||
self.assertRaises(RuntimeError, bam_run, ["checkout", file_name, "--output", session_path], session_path)
|
||||
|
||||
def test_update_blank(self):
|
||||
session_name = "mysession"
|
||||
proj_path, session_path = self.init_session(session_name)
|
||||
|
Reference in New Issue
Block a user