Skip to content

scap deploy: Fail gracefully if run outside of a git repository

Previously, when scap deploy was run in a directory that's not the top
level of a git repository containing a scap/scap.cfg file, it would
fail with a terrible stack trace after creating a scap subdirectory
and an empty log file within it. Now it generates a simple error
message to explain the situation to the user, doesn't generate a stack
trace, and doesn't create any files/directories.

Also:
Class Deploy:
Moved the _load_config() and _setup_loggers() methods before
the main() method to emphasize the order in which they are run.

Old:

debian@deploy:~$ mkdir xxx && cd xxx  
debian@deploy:~/xxx$ scap deploy  
WARNING:deploy:Unhandled error:  
Traceback (most recent call last):  
  File "/workspace/scap/scap/cli.py", line 538, in run  
    app.setup()  
  File "/workspace/scap/scap/cli.py", line 236, in setup  
    self._load_config(use_global_config=use_global_config)  
  File "/workspace/scap/scap/deploy.py", line 1177, in _load_config  
    self.context.setup()  
  File "/workspace/scap/scap/context.py", line 118, in setup  
    os.mkdir(d)  
FileNotFoundError: [Errno 2] No such file or directory: '/home/debian/xxx/.git/config-files'  
ERROR:deploy:deploy failed: <FileNotFoundError> [Errno 2] No such file or directory: '/home/debian/xxx/.git/config-files'  
debian@deploy:~/xxx$ ls -lR  
.:  
total 4  
drwxrwxr-x 3 debian wikidev 4096 Jun  6 20:00 scap  
  
./scap:  
total 4  
drwxrwxr-x 2 debian wikidev 4096 Jun  6 20:00 log  
  
./scap/log:  
total 0  

New:

debian@deploy:~/xxx$ scap deploy  
Deployment configuration not found.  
For `scap deploy` to work, the current directory must be the top level of a git repo containing a scap/scap.cfg file.  
debian@deploy:~/xxx$ ls -lR  
.:  
total 0  
Edited by Ahmon Dancy

Merge request reports