forked from mage-ai/mage-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dy] Fix git integration bugs (mage-ai#2199)
* [dy] Fix bugs * [dy] Fix lint
- Loading branch information
Showing
8 changed files
with
303 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,20 @@ | ||
from mage_ai.data_preparation.git import Git | ||
from mage_ai.data_preparation.sync import GitConfig | ||
from mage_ai.data_preparation.sync.base_sync import BaseSync | ||
from mage_ai.shared.logger import VerboseFunctionExec | ||
import git | ||
import subprocess | ||
import asyncio | ||
|
||
|
||
class GitSync(BaseSync): | ||
def __init__(self, sync_config: GitConfig): | ||
self.remote_repo_link = sync_config.remote_repo_link | ||
self.repo_path = sync_config.repo_path | ||
self.branch = sync_config.branch | ||
try: | ||
self.repo = git.Repo(self.repo_path) | ||
except git.exc.InvalidGitRepositoryError: | ||
self.repo = git.Repo.init(self.repo_path) | ||
|
||
try: | ||
self.repo.create_remote('origin', self.remote_repo_link) | ||
except git.exc.GitCommandError: | ||
# if the remote already exists | ||
self.repo.remotes.origin.set_url(self.remote_repo_link) | ||
|
||
self.origin = self.repo.remotes.origin | ||
self.remote_repo_link = sync_config.remote_repo_link | ||
self.git_manager = Git(sync_config) | ||
|
||
def sync_data(self): | ||
with VerboseFunctionExec( | ||
f'Syncing data with remote repo {self.remote_repo_link}', | ||
verbose=True, | ||
): | ||
# use subprocess because the gitpython command wasn't timing out correctly | ||
subprocess.run( | ||
['git', 'fetch', self.origin.name], | ||
cwd=self.repo_path, | ||
timeout=30, | ||
) | ||
self.repo.git.reset('--hard', f'{self.origin.name}/{self.branch}') | ||
asyncio.run(self.git_manager.check_connection()) | ||
self.git_manager.reset(self.branch) |
Oops, something went wrong.