File size: 751 Bytes
7393a38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import subprocess
from pathlib import Path
import logging
import os

logger = logging.getLogger(__name__)


def pack_code(git_root, run_dir):
    if os.path.isdir(f"{git_root}/.git"):
        subprocess.run(
            ['git', 'archive', '-o', f"{run_dir}/code.tar.gz", 'HEAD'],
            check=True,
        )
        diff_process = subprocess.run(
            ['git', 'diff', 'HEAD'],
            check=True, stdout=subprocess.PIPE, text=True,
        )
        if diff_process.stdout:
            logger.warning('Working tree is dirty. Patch:\n%s', diff_process.stdout)
            with open(f"{run_dir}/dirty.patch", 'w') as f:
                f.write(diff_process.stdout)
    else:
        logger.warning('.git does not exist in current dir')