33
def resolve_homedir_file( file ):
34
"""Given a filename, which could be absolute or relative to the CWD, this
35
returns a pair of 'resolved' filenames: the name of the file relative to
36
the homedir and the full, absolute filename. Neither of the returned
37
filenames are guaranteed nor required to exist. But the supplied
38
filename will cause an error if it is not iteself or when resolved (if
39
it is a symlink) under the homedirectory.
42
home_dir_prefix = os.path.realpath( the.full_home_dir ) + os.sep
44
# obtain absolute filename
45
abs_file = os.path.abspath( file )
47
# if absolute filename is not under home directory, attempt to
49
if abs_file[ : len( home_dir_prefix ) ] != home_dir_prefix:
50
parts = os.path.split( file )
51
if os.path.exists( parts[ 0 ] ):
52
abs_file = os.path.join(
53
os.path.realpath( parts[ 0 ] ), parts[ 1 ] )
55
# absolute file must now be under home directory and exist
56
if abs_file[ : len( home_dir_prefix ) ] != home_dir_prefix:
57
raise the.program.FatalError(
58
'not under home directory: %s' % file )
61
rel_file = abs_file[ len( home_dir_prefix ) : ]
63
return ( rel_file, abs_file )
67
def expand_files( cls, files, recurse = True ):
32
def expand_files( files, recurse = True ):
68
33
"""Returns a unique, sorted list of relative files, calculated from the list
69
34
provided, which is made up from individual files and directories
70
35
relative to the CWD (and which must be contained within the home
43
home_dir_prefix = os.path.realpath( the.full_home_dir ) + os.sep
79
45
# iterate through file list
81
( rel_file, abs_file ) = cls.resolve_homedir_file( file )
83
# check that file exists in repository
47
parts = os.path.split( file )
48
abs_file = os.path.join(
49
os.path.realpath( parts[ 0 ] ), parts[ 1 ] )
51
# check the file is in the home directory
52
if abs_file[ : len( home_dir_prefix ) ] != home_dir_prefix:
53
raise the.program.FatalError(
54
'not under home directory: %s' % abs_file )
57
rel_file = abs_file[ len( home_dir_prefix ) : ]
59
# check if file exists in repository
84
60
repo_file = os.path.join( the.repo.full_dir, rel_file )
85
61
if not os.path.lexists( repo_file ):
86
62
raise the.program.FatalError(
91
67
the.repo.full_dir, rel_file, recurse ) )
93
69
return sorted( set ( ret ) )
97
def print_stage_commands_notice():
98
# 01234567890123456789012345678901234567890123456789012345678901234567890123456789
99
print("In addition to using the primary commands (such as add and remove) to modify a")
100
print("remote repository, you can also set up changes in the local repository and")
101
print("manually commit them in one go to a remote repository when you're ready. This")
102
print("is done with the staging commands. Note, some primary commands will not work")
103
print("when there are staged changes. You can revert all staged changes with the")
104
print("stage-revert command.")