Repository: getnikola/nikola
Issue: UnboundLocalError exception in `nikola deploy`

<!--
Before creating an issue:
* make sure you are using an up-to-date version of Nikola
* search for existing issues that might be related

Make sure to:
* provide information about your environment (below)
* include all the output you get, and any other information related to your problem

Nikola v7.6.4, as provided by Ubuntu, is NOT SUPPORTED.
If you are using this version, you should upgrade: https://getnikola.com/getting-started.html
-->

### Environment

**Python Version:**

Python 3.7.9

**Nikola Version:**

Nikola v8.1.2 (installed from git master)

**Operating System:** 

FreeBSD 12.2-RELEASE amd64

### Description:

On running `nikola deploy` on a new site, after rsync completes, this exception is thrown:

```python
  File "[...]/nikola/nikola/plugins/command/deploy.py", line 99, in _execute
    self._emit_deploy_event(last_deploy, new_deploy, clean, undeployed_posts)
UnboundLocalError: local variable 'clean' referenced before assignment
```

I looked at the source and noticed that `clean` is only set inside a condition:

https://github.com/getnikola/nikola/blob/d0ef5b68d0667f635ecb2bc0d5b92e480b5e4b25/nikola/plugins/command/deploy.py#L50-L56

To try and fix it, I changed the source to:

```python
        if last_deploy is not None:
            last_deploy = dateutil.parser.parse(last_deploy)
            clean = False
        else:
            clean = True
```

That leads to another exception elsewhere:

```python
  File "[...]/nikola/nikola/plugins/command/deploy.py", line 131, in _emit_deploy_event
    if last_deploy.tzinfo is None:
AttributeError: 'NoneType' object has no attribute 'tzinfo'
```

Which was fixed by changing the source code at:

https://github.com/getnikola/nikola/blob/d0ef5b68d0667f635ecb2bc0d5b92e480b5e4b25/nikola/plugins/command/deploy.py#L98-L99

to:

```python
        new_deploy = datetime.utcnow()
        if last_deploy is None:
            last_deploy = new_deploy
        self._emit_deploy_event(last_deploy, new_deploy, clean, undeployed_posts)
```

After this the deploy command has worked as I expected.

Changed files:
nikola/plugins/command/deploy.py

diff --git a/nikola/plugins/command/deploy.py b/nikola/plugins/command/deploy.py
index 5273b58dd..11a0c9bf1 100644
--- a/nikola/plugins/command/deploy.py
+++ b/nikola/plugins/command/deploy.py
@@ -54,6 +54,8 @@ class CommandDeploy(Command):
         if last_deploy is not None:
             last_deploy = dateutil.parser.parse(last_deploy)
             clean = False
+        else:
+            clean = True
 
         if self.site.config['COMMENT_SYSTEM'] and self.site.config['COMMENT_SYSTEM_ID'] == 'nikolademo':
             self.logger.warning("\\nWARNING WARNING WARNING WARNING\\n"
@@ -96,6 +98,8 @@ class CommandDeploy(Command):
         self.logger.info("Successful deployment")
 
         new_deploy = datetime.utcnow()
+        if last_deploy is None:
+            last_deploy = new_deploy
         self._emit_deploy_event(last_deploy, new_deploy, clean, undeployed_posts)
 
         # Store timestamp of successful deployment