'GitPython - script error - already exists and is not an empty directory
I have a script that makes a clone of the repository I need. This script must be executed every day, i.e. reload data from the repository. There are no problems with cloning itself - the first launch downloads all the necessary files. But the next one knocks out this error.
stderr: 'fatal: destination path 'C:/Users/tred1/Desktop/WORK/анализатор/GHR_Y00011450/Data' already exists and is not an empty directory.
Those. I cannot clone a directory to a folder where it already exists. Which sounds pretty logical. I'm just learning how to work with git and sometimes I don't quite understand the commands.
Here is some of the code that does the cloning
class CloneProgress(RemoteProgress):
def update(self, op_code, cur_count, max_count=None, message=''):
pbar = tqdm(total=max_count)
pbar.update(cur_count)
def save (source, directory):
Repo.clone_from(source, directory, branch='master', progress=CloneProgress())
How can I update and add new files from this directory to bypass this error? Maybe there is some method?
Solution 1:[1]
If you want to udpate an already cloned repo you do a pull
def save (source, directory):
if not os.path.exists(directory):
Repo.clone_from(source, directory, branch='master', progress=CloneProgress())
else:
repo = Repo(directory)
repo.remotes[0].pull()
Solution 2:[2]
hm, I think it can help you Explanation
This is pretty vague but I'll do what I can to help.
First, while it may seem daunting at first, I suggest you learn how to do things from the command line (called terminal on OSX). This is a great way to make sure you're putting things where you really want to.
You should definitely google 'unix commands' to learn more, but here are a few important commands to help in this situation:
ls - list all files and directories (folders) in current directory
cd - change directory, or change the folder you're looking in
mkdir - Makes a new directory (be careful, you will have to cd into the directory after you make it)
rm -r - Removes a directory and everything inside it
git clone - Clones the repository into the directory you are currently browsing.
Answer
So, on my computer, I would run the following commands to create a directory (folder) called projects within my documents folder and clone a repo there.
Open terminal cd documents (Not case sensitive on mac) mkdir projects cd projects git clone https://github.com/seanbecker15/wherecanifindit.git cd wherecanifindit (if I want to go into the directory) p.s. wherecanifindit is just the name of my git repository, not a command!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Adam Georgsson |
Solution 2 | Sasha Mikayelyan |