Initial implementation for commit, push, fetch.
parent
360120b1f0
commit
e0ff8404b5
117
gitlib/gitlib.py
117
gitlib/gitlib.py
|
@ -1278,6 +1278,33 @@ class OpengnsysGitLibrary:
|
|||
repo.config_writer().add_value("user", "email", "OpenGnsys@opengnsys.com").release()
|
||||
repo.config_writer().add_value("core", "filemode", "false").release()
|
||||
|
||||
def _ensure_mounted(self, device):
|
||||
|
||||
self.logger.info("Mounting %s", device)
|
||||
|
||||
self._unmount_device(device)
|
||||
path = os.path.join("/mnt", os.path.basename(device))
|
||||
|
||||
self.logger.debug(f"Will mount repo at {path}")
|
||||
if not os.path.exists(path):
|
||||
os.mkdir(path)
|
||||
|
||||
if self._filesystem_type(device) == "ntfs":
|
||||
self.logger.debug("Handing a NTFS filesystem")
|
||||
|
||||
self._modprobe("ntfs3")
|
||||
self._ntfsfix(device)
|
||||
|
||||
ntfs = NTFSLibrary(self.ntfs_implementation)
|
||||
ntfs.mount_filesystem(device, path)
|
||||
|
||||
else:
|
||||
self.logger.debug("Handling a non-NTFS filesystem")
|
||||
self._mount(device, path)
|
||||
|
||||
self.logger.debug("Successfully mounted at %s", path)
|
||||
return path
|
||||
|
||||
def initRepo(self, device, repo_name):
|
||||
"""
|
||||
Initialize a Git repository on a specified device.
|
||||
|
@ -1299,29 +1326,7 @@ class OpengnsysGitLibrary:
|
|||
- The method sets up a remote origin and pushes the initial commit.
|
||||
"""
|
||||
|
||||
self._unmount_device(device)
|
||||
path = os.path.join("/mnt", os.path.basename(device))
|
||||
|
||||
|
||||
self.logger.debug(f"Will mount repo at {path}")
|
||||
if not os.path.exists(path):
|
||||
os.mkdir(path)
|
||||
|
||||
|
||||
|
||||
if self._filesystem_type(device) == "ntfs":
|
||||
self.logger.debug("Handing a NTFS filesystem")
|
||||
|
||||
self._modprobe("ntfs3")
|
||||
self._ntfsfix(device)
|
||||
|
||||
ntfs = NTFSLibrary(self.ntfs_implementation)
|
||||
ntfs.mount_filesystem(device, path)
|
||||
|
||||
else:
|
||||
self._mount(device, path)
|
||||
|
||||
|
||||
path = self._ensure_mounted(device)
|
||||
self.logger.info("Initializing repository: %s", path)
|
||||
|
||||
git_dir = os.path.join(path, ".git")
|
||||
|
@ -1515,13 +1520,24 @@ class OpengnsysGitLibrary:
|
|||
self._restore_metadata(destination_dir)
|
||||
|
||||
|
||||
def commitRepo(self, path):
|
||||
def commit(self, path = None, device = None, message = None):
|
||||
"""
|
||||
Commit all current changes to the local data
|
||||
"""
|
||||
|
||||
if path is None:
|
||||
path = self._ensure_mounted(device)
|
||||
|
||||
self.logger.info("Committing changes to repository")
|
||||
repo = git.Repo(path)
|
||||
|
||||
metadata_ret = self._create_metadata(path)
|
||||
self._create_metadata(path)
|
||||
|
||||
self.logger.info("Adding files")
|
||||
repo.index.add("*")
|
||||
|
||||
self.logger.info("Creating commit")
|
||||
repo.index.commit(message)
|
||||
|
||||
# Restaurar cosas modificadas para git
|
||||
self._restore_metadata(path, destructive_only=True)
|
||||
|
@ -1538,17 +1554,43 @@ class OpengnsysGitLibrary:
|
|||
# Restaurar cosas modificadas para git
|
||||
self._restore_metadata(path, destructive_only=True)
|
||||
|
||||
def pushRepo(self, path):
|
||||
def push(self, path = None, device = None):
|
||||
"""
|
||||
Push local changes to ogrepository
|
||||
|
||||
Use commitRepo() first to save local changes.
|
||||
Use commit() first to save local changes.
|
||||
"""
|
||||
|
||||
|
||||
if path is None:
|
||||
path = self._ensure_mounted(device)
|
||||
|
||||
repo = git.Repo(path)
|
||||
|
||||
self.logger.debug("Uploading to ogrepository")
|
||||
self.logger.info("Uploading to ogrepository")
|
||||
repo.git.push("--set-upstream", "origin", repo.head.ref, "--force") # force = True)
|
||||
|
||||
|
||||
def fetch(self, path = None, device = None):
|
||||
"""
|
||||
Fetch updates from ogrepository. Doesn't change the filesystem.
|
||||
"""
|
||||
|
||||
|
||||
if path is None:
|
||||
path = self._ensure_mounted(device)
|
||||
|
||||
repo = git.Repo(path)
|
||||
|
||||
self.logger.info("Fetching from ogrepository")
|
||||
origin = repo.remotes.origin
|
||||
|
||||
if origin:
|
||||
self.logger.debug("Fetching from origin")
|
||||
origin.fetch()
|
||||
else:
|
||||
self.logger.error("Origin not found, can't fetch")
|
||||
|
||||
def pullRepo(self, path):
|
||||
"""
|
||||
Pull changes from ogrepository
|
||||
|
@ -1602,19 +1644,21 @@ if __name__ == '__main__':
|
|||
|
||||
#parser.add_argument("--init-repo", type=str, metavar='DIR', help="Inicializar repositorio desde DIR")
|
||||
parser.add_argument("--init-repo-from", type=str, metavar='DEV', help="Inicializar repositorio desde DEV")
|
||||
parser.add_argument("--clone-repo-to", type=str, metavar='DIR', help="Clonar repositorio a DIR. Elimina todos los datos en ruta destino!")
|
||||
parser.add_argument("--clone-repo-to", type=str, metavar='DEV', help="Clonar repositorio a DIR. Elimina todos los datos en ruta destino!")
|
||||
parser.add_argument("--repo", type=str, help="Repositorio en ogrepository (linux, windows, mac)")
|
||||
parser.add_argument("--boot-device", type=str, help="Dispositivo de arranque")
|
||||
parser.add_argument("--commit", type=str, metavar='DIR', help="Commit de cambios en el directorio")
|
||||
parser.add_argument("--restore", type=str, metavar='DIR', help="Eliminar cambios en el directorio")
|
||||
parser.add_argument("--push", type=str, metavar='DIR', help="Subir cambios a ogrepository")
|
||||
parser.add_argument("--pull", type=str, metavar='DIR', help="Bajar cambios de ogrepository")
|
||||
parser.add_argument("--commit", type=str, metavar='DEV', help="Commit de cambios en el directorio")
|
||||
parser.add_argument("--restore", type=str, metavar='DEV', help="Eliminar cambios en el directorio")
|
||||
parser.add_argument("--push", type=str, metavar='DEV', help="Subir cambios a ogrepository")
|
||||
parser.add_argument("--pull", type=str, metavar='DEV', help="Bajar cambios de ogrepository")
|
||||
parser.add_argument("--fetch", type=str, metavar='DEV', help="Fetch changes from ogrepository")
|
||||
|
||||
parser.add_argument("--ntfs-type", type=str, metavar="FS", help="Tipo de NTFS, 'kernel' o 'fuse'")
|
||||
parser.add_argument("--test-metadata", type=str, metavar="DIR", help="Test metadata generation")
|
||||
parser.add_argument("--test-restore-metadata", type=str, metavar="DIR", help="Test metadata restoration")
|
||||
parser.add_argument("--test-restore-metadata-destructive", type=str, metavar="DIR", help="Test metadata restoration, destructive parts only")
|
||||
parser.add_argument("--test-clone-metadata", type=str, metavar="REPO", help="Test metadata cloning")
|
||||
parser.add_argument("-m", "--message", type=str, metavar="MSG", help="Commit message")
|
||||
|
||||
parser.add_argument("-v", "--verbose", action="store_true", help = "Verbose console output")
|
||||
|
||||
|
@ -1656,13 +1700,16 @@ if __name__ == '__main__':
|
|||
#og_git._restore_metadata(args.clone_repo_to)
|
||||
elif args.commit:
|
||||
with OperationTimer(og_git, "git commit"):
|
||||
og_git.commitRepo(args.commit)
|
||||
og_git.commit(device = args.commit, message = args.message)
|
||||
elif args.restore:
|
||||
with OperationTimer(og_git, "git restore"):
|
||||
og_git.restoreRepo(args.restore)
|
||||
elif args.push:
|
||||
with OperationTimer(og_git, "git push"):
|
||||
og_git.pushRepo(args.push)
|
||||
og_git.push(device = args.push)
|
||||
elif args.fetch:
|
||||
with OperationTimer(og_git, "git fetch"):
|
||||
og_git.fetch(device = args.fetch)
|
||||
elif args.pull:
|
||||
with OperationTimer(og_git, "git pull"):
|
||||
og_git.pullRepo(args.pull)
|
||||
|
|
Loading…
Reference in New Issue