githydra 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of githydra might be problematic. Click here for more details.
- githydra/__init__.py +17 -0
- githydra/__main__.py +289 -0
- githydra/analytics/__init__.py +10 -0
- githydra/analytics/code_analysis.py +18 -0
- githydra/analytics/history.py +21 -0
- githydra/analytics/stats.py +27 -0
- githydra/core/__init__.py +10 -0
- githydra/core/config.py +143 -0
- githydra/core/repository.py +107 -0
- githydra/core/session.py +63 -0
- githydra/help/__init__.py +9 -0
- githydra/help/guides.py +31 -0
- githydra/help/tutorials.py +16 -0
- githydra/localization/__init__.py +9 -0
- githydra/localization/ar.py +31 -0
- githydra/localization/en.py +31 -0
- githydra/operations/__init__.py +11 -0
- githydra/operations/branch.py +28 -0
- githydra/operations/commit.py +25 -0
- githydra/operations/merge.py +24 -0
- githydra/operations/remote.py +24 -0
- githydra/ui/__init__.py +10 -0
- githydra/ui/display.py +268 -0
- githydra/ui/menu.py +109 -0
- githydra/ui/progress.py +97 -0
- githydra/utils/__init__.py +11 -0
- githydra/utils/helpers.py +185 -0
- githydra/utils/logger.py +225 -0
- githydra/utils/validators.py +177 -0
- githydra-1.0.0.dist-info/METADATA +170 -0
- githydra-1.0.0.dist-info/RECORD +35 -0
- githydra-1.0.0.dist-info/WHEEL +5 -0
- githydra-1.0.0.dist-info/entry_points.txt +2 -0
- githydra-1.0.0.dist-info/licenses/LICENSE +26 -0
- githydra-1.0.0.dist-info/top_level.txt +1 -0
githydra/__init__.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""
|
|
2
|
+
GitHydra - Advanced Git Repository Management Tool
|
|
3
|
+
Author: Abdulaziz Alqudimi
|
|
4
|
+
Version: 1.0.0
|
|
5
|
+
|
|
6
|
+
A powerful, professional Git management tool with beautiful UI,
|
|
7
|
+
comprehensive logging, and intelligent automation.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
__version__ = "1.0.0"
|
|
11
|
+
__author__ = "Abdulaziz Alqudimi"
|
|
12
|
+
__description__ = "Advanced Git Repository Management Tool"
|
|
13
|
+
|
|
14
|
+
from githydra.core.repository import RepositoryManager
|
|
15
|
+
from githydra.ui.display import DisplayManager
|
|
16
|
+
|
|
17
|
+
__all__ = ["RepositoryManager", "DisplayManager"]
|
githydra/__main__.py
ADDED
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"""
|
|
2
|
+
GitHydra - Advanced Git Repository Manager
|
|
3
|
+
Author: Abdulaziz Alqudimi
|
|
4
|
+
Version: 1.0.0
|
|
5
|
+
|
|
6
|
+
Main entry point for the application.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import sys
|
|
10
|
+
import argparse
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from githydra.core.repository import RepositoryManager
|
|
14
|
+
from githydra.core.config import ConfigurationManager
|
|
15
|
+
from githydra.core.session import SessionManager
|
|
16
|
+
from githydra.ui.display import DisplayManager
|
|
17
|
+
from githydra.ui.menu import MenuSystem
|
|
18
|
+
from githydra.ui.progress import ProgressBarManager
|
|
19
|
+
from githydra.utils.logger import LoggingSystem
|
|
20
|
+
from githydra.localization.ar import ARABIC_TRANSLATIONS
|
|
21
|
+
from githydra.localization.en import ENGLISH_TRANSLATIONS
|
|
22
|
+
from githydra.operations.commit import CommitController
|
|
23
|
+
from githydra.operations.branch import BranchController
|
|
24
|
+
from githydra.operations.remote import RemoteController
|
|
25
|
+
from githydra.analytics.stats import StatisticsAnalyzer
|
|
26
|
+
from githydra.help.guides import HelpGuides
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class GitHydra:
|
|
30
|
+
"""
|
|
31
|
+
Main application class for GitHydra.
|
|
32
|
+
|
|
33
|
+
Args:
|
|
34
|
+
repo_path (str): Path to Git repository
|
|
35
|
+
language (str): Interface language ('ar' or 'en')
|
|
36
|
+
|
|
37
|
+
Returns:
|
|
38
|
+
GitHydra: Application instance
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def __init__(self, repo_path: str = ".", language: str = "ar"):
|
|
42
|
+
self.logger = LoggingSystem()
|
|
43
|
+
self.config = ConfigurationManager()
|
|
44
|
+
self.session = SessionManager()
|
|
45
|
+
self.display = DisplayManager()
|
|
46
|
+
|
|
47
|
+
self.language = language or self.config.get("language", "ar")
|
|
48
|
+
self.translations = ARABIC_TRANSLATIONS if self.language == "ar" else ENGLISH_TRANSLATIONS
|
|
49
|
+
|
|
50
|
+
self.repo_manager = RepositoryManager(repo_path, self.config, self.session)
|
|
51
|
+
self.menu = MenuSystem(self.display, self.translate)
|
|
52
|
+
self.progress = ProgressBarManager(self.display.console)
|
|
53
|
+
|
|
54
|
+
self.commit_controller = CommitController(self.repo_manager.repo)
|
|
55
|
+
self.branch_controller = BranchController(self.repo_manager.repo)
|
|
56
|
+
self.remote_controller = RemoteController(self.repo_manager.repo)
|
|
57
|
+
self.stats_analyzer = StatisticsAnalyzer(self.repo_manager.repo)
|
|
58
|
+
self.help_guides = HelpGuides(self.translate)
|
|
59
|
+
|
|
60
|
+
self.logger.info("GitHydra application initialized")
|
|
61
|
+
|
|
62
|
+
def translate(self, key: str, *args) -> str:
|
|
63
|
+
"""
|
|
64
|
+
Translate text to current language.
|
|
65
|
+
|
|
66
|
+
Args:
|
|
67
|
+
key (str): Translation key
|
|
68
|
+
*args: Format arguments
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
str: Translated text
|
|
72
|
+
"""
|
|
73
|
+
text = self.translations.get(key, key)
|
|
74
|
+
if args:
|
|
75
|
+
try:
|
|
76
|
+
return text.format(*args)
|
|
77
|
+
except:
|
|
78
|
+
return text
|
|
79
|
+
return text
|
|
80
|
+
|
|
81
|
+
def run(self) -> None:
|
|
82
|
+
"""
|
|
83
|
+
Run the main application loop.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
None
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
None
|
|
90
|
+
"""
|
|
91
|
+
self.display.print_banner()
|
|
92
|
+
self.logger.info("Application started")
|
|
93
|
+
|
|
94
|
+
while True:
|
|
95
|
+
try:
|
|
96
|
+
status = self.repo_manager.get_status()
|
|
97
|
+
branch = self.repo_manager.get_current_branch()
|
|
98
|
+
changes = len(status['staged']) + len(status['modified']) + len(status['untracked'])
|
|
99
|
+
sync_status = "[synced]"
|
|
100
|
+
|
|
101
|
+
choice = self.menu.show_main_menu(branch, changes, sync_status)
|
|
102
|
+
|
|
103
|
+
if choice == "0":
|
|
104
|
+
self.display.print_success(self.translate('goodbye'))
|
|
105
|
+
self.session.save_session()
|
|
106
|
+
break
|
|
107
|
+
elif choice == "1":
|
|
108
|
+
self.show_status()
|
|
109
|
+
elif choice == "2":
|
|
110
|
+
self.smart_add()
|
|
111
|
+
elif choice == "3":
|
|
112
|
+
self.commit()
|
|
113
|
+
elif choice == "4":
|
|
114
|
+
self.push()
|
|
115
|
+
elif choice == "5":
|
|
116
|
+
self.pull()
|
|
117
|
+
elif choice == "6":
|
|
118
|
+
self.show_log()
|
|
119
|
+
elif choice == "7":
|
|
120
|
+
self.manage_branches()
|
|
121
|
+
elif choice == "8":
|
|
122
|
+
self.show_repo_info()
|
|
123
|
+
elif choice == "18":
|
|
124
|
+
self.show_help()
|
|
125
|
+
else:
|
|
126
|
+
self.display.print_info("Feature coming soon!")
|
|
127
|
+
|
|
128
|
+
input(self.translate('press_enter'))
|
|
129
|
+
|
|
130
|
+
except KeyboardInterrupt:
|
|
131
|
+
self.display.print_warning(self.translate('operation_cancelled'))
|
|
132
|
+
break
|
|
133
|
+
except Exception as e:
|
|
134
|
+
self.display.print_error(self.translate('unexpected_error', str(e)))
|
|
135
|
+
self.logger.error(f"Application error: {e}", exc_info=True)
|
|
136
|
+
input(self.translate('press_enter'))
|
|
137
|
+
|
|
138
|
+
def show_status(self) -> None:
|
|
139
|
+
"""Show repository status."""
|
|
140
|
+
status = self.repo_manager.get_status()
|
|
141
|
+
|
|
142
|
+
self.display.print_header("Repository Status", "📊")
|
|
143
|
+
self.display.print_info(f"Branch: {status['branch']}")
|
|
144
|
+
|
|
145
|
+
if status['staged']:
|
|
146
|
+
self.display.print_success(f"Staged files: {len(status['staged'])}")
|
|
147
|
+
for file in status['staged'][:5]:
|
|
148
|
+
self.display.console.print(f" ✅ {file}")
|
|
149
|
+
|
|
150
|
+
if status['modified']:
|
|
151
|
+
self.display.print_warning(f"Modified files: {len(status['modified'])}")
|
|
152
|
+
for file in status['modified'][:5]:
|
|
153
|
+
self.display.console.print(f" 📝 {file}")
|
|
154
|
+
|
|
155
|
+
if status['untracked']:
|
|
156
|
+
self.display.print_info(f"Untracked files: {len(status['untracked'])}")
|
|
157
|
+
for file in status['untracked'][:5]:
|
|
158
|
+
self.display.console.print(f" 🆕 {file}")
|
|
159
|
+
|
|
160
|
+
def smart_add(self) -> None:
|
|
161
|
+
"""Smart add files."""
|
|
162
|
+
self.display.print_header(self.translate('smart_add_title'), "📦")
|
|
163
|
+
status = self.repo_manager.get_status()
|
|
164
|
+
|
|
165
|
+
all_files = status['modified'] + status['untracked']
|
|
166
|
+
if not all_files:
|
|
167
|
+
self.display.print_info(self.translate('no_changes'))
|
|
168
|
+
return
|
|
169
|
+
|
|
170
|
+
self.display.console.print(f"Found {len(all_files)} files:")
|
|
171
|
+
for i, file in enumerate(all_files, 1):
|
|
172
|
+
self.display.console.print(f" {i}. {file}")
|
|
173
|
+
|
|
174
|
+
choice = self.display.prompt("Add all files? (y/n)")
|
|
175
|
+
if choice.lower() == 'y':
|
|
176
|
+
try:
|
|
177
|
+
self.repo_manager.repo.git.add('.')
|
|
178
|
+
self.display.print_success("All files added to staging")
|
|
179
|
+
self.logger.log_operation("add", "success", "all files")
|
|
180
|
+
except Exception as e:
|
|
181
|
+
self.display.print_error(f"Failed to add files: {e}")
|
|
182
|
+
self.logger.log_operation("add", "failed", str(e))
|
|
183
|
+
|
|
184
|
+
def commit(self) -> None:
|
|
185
|
+
"""Commit changes."""
|
|
186
|
+
self.display.print_header(self.translate('commit_title'), "💾")
|
|
187
|
+
|
|
188
|
+
status = self.repo_manager.get_status()
|
|
189
|
+
if not status['staged'] and not status['modified']:
|
|
190
|
+
self.display.print_info(self.translate('no_changes'))
|
|
191
|
+
return
|
|
192
|
+
|
|
193
|
+
message = self.display.prompt("Enter commit message")
|
|
194
|
+
if message:
|
|
195
|
+
if self.commit_controller.commit(message):
|
|
196
|
+
self.display.print_success(self.translate('commit_success', message[:50]))
|
|
197
|
+
else:
|
|
198
|
+
self.display.print_error("Failed to commit")
|
|
199
|
+
|
|
200
|
+
def push(self) -> None:
|
|
201
|
+
"""Push changes."""
|
|
202
|
+
try:
|
|
203
|
+
self.repo_manager.repo.git.push()
|
|
204
|
+
self.display.print_success(self.translate('push_success'))
|
|
205
|
+
self.logger.log_operation("push", "success", "")
|
|
206
|
+
except Exception as e:
|
|
207
|
+
self.display.print_error(f"Push failed: {e}")
|
|
208
|
+
self.logger.log_operation("push", "failed", str(e))
|
|
209
|
+
|
|
210
|
+
def pull(self) -> None:
|
|
211
|
+
"""Pull changes."""
|
|
212
|
+
try:
|
|
213
|
+
self.repo_manager.repo.git.pull()
|
|
214
|
+
self.display.print_success(self.translate('pull_success'))
|
|
215
|
+
self.logger.log_operation("pull", "success", "")
|
|
216
|
+
except Exception as e:
|
|
217
|
+
self.display.print_error(f"Pull failed: {e}")
|
|
218
|
+
self.logger.log_operation("pull", "failed", str(e))
|
|
219
|
+
|
|
220
|
+
def show_log(self) -> None:
|
|
221
|
+
"""Show commit log."""
|
|
222
|
+
self.display.print_header("Commit History", "📜")
|
|
223
|
+
try:
|
|
224
|
+
commits = list(self.repo_manager.repo.iter_commits(max_count=10))
|
|
225
|
+
for commit in commits:
|
|
226
|
+
self.display.console.print(
|
|
227
|
+
f"[cyan]{commit.hexsha[:8]}[/] - "
|
|
228
|
+
f"[yellow]{commit.author.name}[/] - "
|
|
229
|
+
f"{commit.message.strip()}"
|
|
230
|
+
)
|
|
231
|
+
except Exception as e:
|
|
232
|
+
self.display.print_error(f"Failed to get log: {e}")
|
|
233
|
+
|
|
234
|
+
def manage_branches(self) -> None:
|
|
235
|
+
"""Manage branches."""
|
|
236
|
+
self.display.print_header("Branch Management", "🌿")
|
|
237
|
+
branches = self.branch_controller.list_branches()
|
|
238
|
+
current = self.repo_manager.get_current_branch()
|
|
239
|
+
|
|
240
|
+
for branch in branches:
|
|
241
|
+
marker = "* " if branch == current else " "
|
|
242
|
+
self.display.console.print(f"{marker}[cyan]{branch}[/]")
|
|
243
|
+
|
|
244
|
+
def show_repo_info(self) -> None:
|
|
245
|
+
"""Show repository info."""
|
|
246
|
+
self.display.print_header("Repository Information", "🏠")
|
|
247
|
+
stats = self.stats_analyzer.get_commit_stats()
|
|
248
|
+
|
|
249
|
+
self.display.console.print(f"Total commits: [cyan]{stats['total_commits']}[/]")
|
|
250
|
+
self.display.console.print(f"Contributors: [cyan]{stats['contributors']}[/]")
|
|
251
|
+
|
|
252
|
+
def show_help(self) -> None:
|
|
253
|
+
"""Show help."""
|
|
254
|
+
help_text = self.help_guides.get_basic_help()
|
|
255
|
+
self.display.print_panel(help_text, title="📚 Help", border_style="green")
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
def main():
|
|
259
|
+
"""
|
|
260
|
+
Main entry point.
|
|
261
|
+
|
|
262
|
+
Args:
|
|
263
|
+
None
|
|
264
|
+
|
|
265
|
+
Returns:
|
|
266
|
+
None
|
|
267
|
+
"""
|
|
268
|
+
parser = argparse.ArgumentParser(
|
|
269
|
+
description='GitHydra - Advanced Git Repository Manager by Abdulaziz Alqudimi'
|
|
270
|
+
)
|
|
271
|
+
parser.add_argument('--repo', '-r', default='.', help='Repository path')
|
|
272
|
+
parser.add_argument('--language', '-l', choices=['ar', 'en'], default='ar',
|
|
273
|
+
help='Interface language')
|
|
274
|
+
parser.add_argument('--version', '-v', action='version', version='GitHydra 1.0.0')
|
|
275
|
+
|
|
276
|
+
args = parser.parse_args()
|
|
277
|
+
|
|
278
|
+
try:
|
|
279
|
+
app = GitHydra(repo_path=args.repo, language=args.language)
|
|
280
|
+
app.run()
|
|
281
|
+
except KeyboardInterrupt:
|
|
282
|
+
print("\n👋 Goodbye!")
|
|
283
|
+
except Exception as e:
|
|
284
|
+
print(f"❌ Fatal error: {e}")
|
|
285
|
+
sys.exit(1)
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
if __name__ == "__main__":
|
|
289
|
+
main()
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Analytics modules for GitHydra
|
|
3
|
+
Provides statistics, code analysis, and history tracking
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from githydra.analytics.stats import StatisticsAnalyzer
|
|
7
|
+
from githydra.analytics.code_analysis import CodeAnalyzer
|
|
8
|
+
from githydra.analytics.history import HistoryAnalyzer
|
|
9
|
+
|
|
10
|
+
__all__ = ["StatisticsAnalyzer", "CodeAnalyzer", "HistoryAnalyzer"]
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Code analyzer for GitHydra
|
|
3
|
+
Author: Abdulaziz Alqudimi
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from githydra.utils.logger import LoggingSystem
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class CodeAnalyzer:
|
|
10
|
+
"""Analyzes code quality."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, repo):
|
|
13
|
+
self.repo = repo
|
|
14
|
+
self.logger = LoggingSystem()
|
|
15
|
+
|
|
16
|
+
def analyze(self) -> dict:
|
|
17
|
+
"""Analyze code."""
|
|
18
|
+
return {'issues': [], 'suggestions': []}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"""
|
|
2
|
+
History analyzer for GitHydra
|
|
3
|
+
Author: Abdulaziz Alqudimi
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from githydra.utils.logger import LoggingSystem
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class HistoryAnalyzer:
|
|
10
|
+
"""Analyzes repository history."""
|
|
11
|
+
|
|
12
|
+
def __init__(self, repo):
|
|
13
|
+
self.repo = repo
|
|
14
|
+
self.logger = LoggingSystem()
|
|
15
|
+
|
|
16
|
+
def get_history(self, limit: int = 10) -> list:
|
|
17
|
+
"""Get commit history."""
|
|
18
|
+
try:
|
|
19
|
+
return list(self.repo.iter_commits(max_count=limit))
|
|
20
|
+
except:
|
|
21
|
+
return []
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Statistics analyzer for GitHydra
|
|
3
|
+
Author: Abdulaziz Alqudimi
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from datetime import datetime
|
|
7
|
+
from typing import Dict, Any
|
|
8
|
+
from githydra.utils.logger import LoggingSystem
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class StatisticsAnalyzer:
|
|
12
|
+
"""Analyzes repository statistics."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, repo):
|
|
15
|
+
self.repo = repo
|
|
16
|
+
self.logger = LoggingSystem()
|
|
17
|
+
|
|
18
|
+
def get_commit_stats(self) -> Dict[str, Any]:
|
|
19
|
+
"""Get commit statistics."""
|
|
20
|
+
try:
|
|
21
|
+
commits = list(self.repo.iter_commits())
|
|
22
|
+
return {
|
|
23
|
+
'total_commits': len(commits),
|
|
24
|
+
'contributors': len(set(c.author.name for c in commits))
|
|
25
|
+
}
|
|
26
|
+
except:
|
|
27
|
+
return {'total_commits': 0, 'contributors': 0}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Core modules for GitHydra
|
|
3
|
+
Handles repository management, configuration, and session management
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from githydra.core.repository import RepositoryManager
|
|
7
|
+
from githydra.core.config import ConfigurationManager
|
|
8
|
+
from githydra.core.session import SessionManager
|
|
9
|
+
|
|
10
|
+
__all__ = ["RepositoryManager", "ConfigurationManager", "SessionManager"]
|
githydra/core/config.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Configuration manager for GitHydra
|
|
3
|
+
Author: Abdulaziz Alqudimi
|
|
4
|
+
|
|
5
|
+
Manages user configuration and settings.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Dict, Any
|
|
11
|
+
from githydra.utils.logger import LoggingSystem
|
|
12
|
+
from githydra.utils.helpers import ensure_dir_exists
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class ConfigurationManager:
|
|
16
|
+
"""
|
|
17
|
+
Manages user configuration and settings.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
config_dir (Path): Configuration directory path
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
ConfigurationManager: Configuration manager instance
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
def __init__(self, config_dir: Path = None):
|
|
27
|
+
self.config_dir = config_dir or Path.home() / ".githydra"
|
|
28
|
+
self.config_file = self.config_dir / "config.json"
|
|
29
|
+
self.logger = LoggingSystem()
|
|
30
|
+
|
|
31
|
+
ensure_dir_exists(self.config_dir)
|
|
32
|
+
|
|
33
|
+
self.config = self.load_config()
|
|
34
|
+
|
|
35
|
+
def load_config(self) -> Dict[str, Any]:
|
|
36
|
+
"""
|
|
37
|
+
Load configuration from file.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
None
|
|
41
|
+
|
|
42
|
+
Returns:
|
|
43
|
+
Dict[str, Any]: Configuration dictionary
|
|
44
|
+
"""
|
|
45
|
+
if self.config_file.exists():
|
|
46
|
+
try:
|
|
47
|
+
with open(self.config_file, 'r', encoding='utf-8') as f:
|
|
48
|
+
config = json.load(f)
|
|
49
|
+
self.logger.debug("Configuration loaded successfully")
|
|
50
|
+
return config
|
|
51
|
+
except Exception as e:
|
|
52
|
+
self.logger.error(f"Failed to load config: {e}")
|
|
53
|
+
return self._default_config()
|
|
54
|
+
else:
|
|
55
|
+
return self._default_config()
|
|
56
|
+
|
|
57
|
+
def _default_config(self) -> Dict[str, Any]:
|
|
58
|
+
"""
|
|
59
|
+
Get default configuration.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
None
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
Dict[str, Any]: Default configuration dictionary
|
|
66
|
+
"""
|
|
67
|
+
return {
|
|
68
|
+
"language": "ar",
|
|
69
|
+
"auto_add": False,
|
|
70
|
+
"push_after_commit": False,
|
|
71
|
+
"auto_backup": True,
|
|
72
|
+
"show_emojis": True,
|
|
73
|
+
"auto_fetch": False,
|
|
74
|
+
"auto_stash": True,
|
|
75
|
+
"notifications": True,
|
|
76
|
+
"performance_mode": False,
|
|
77
|
+
"preferred_remote": "origin",
|
|
78
|
+
"template_messages": {
|
|
79
|
+
"feature": "feat: {description}",
|
|
80
|
+
"fix": "fix: {description}",
|
|
81
|
+
"docs": "docs: {description}",
|
|
82
|
+
"refactor": "refactor: {description}"
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
def save_config(self) -> None:
|
|
87
|
+
"""
|
|
88
|
+
Save configuration to file.
|
|
89
|
+
|
|
90
|
+
Args:
|
|
91
|
+
None
|
|
92
|
+
|
|
93
|
+
Returns:
|
|
94
|
+
None
|
|
95
|
+
"""
|
|
96
|
+
try:
|
|
97
|
+
with open(self.config_file, 'w', encoding='utf-8') as f:
|
|
98
|
+
json.dump(self.config, f, ensure_ascii=False, indent=2)
|
|
99
|
+
self.logger.info("Configuration saved successfully")
|
|
100
|
+
except Exception as e:
|
|
101
|
+
self.logger.error(f"Failed to save config: {e}", exc_info=True)
|
|
102
|
+
|
|
103
|
+
def get(self, key: str, default: Any = None) -> Any:
|
|
104
|
+
"""
|
|
105
|
+
Get configuration value.
|
|
106
|
+
|
|
107
|
+
Args:
|
|
108
|
+
key (str): Configuration key
|
|
109
|
+
default (Any): Default value if key not found
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
Any: Configuration value
|
|
113
|
+
"""
|
|
114
|
+
return self.config.get(key, default)
|
|
115
|
+
|
|
116
|
+
def set(self, key: str, value: Any) -> None:
|
|
117
|
+
"""
|
|
118
|
+
Set configuration value.
|
|
119
|
+
|
|
120
|
+
Args:
|
|
121
|
+
key (str): Configuration key
|
|
122
|
+
value (Any): Value to set
|
|
123
|
+
|
|
124
|
+
Returns:
|
|
125
|
+
None
|
|
126
|
+
"""
|
|
127
|
+
self.config[key] = value
|
|
128
|
+
self.save_config()
|
|
129
|
+
self.logger.debug(f"Config updated: {key} = {value}")
|
|
130
|
+
|
|
131
|
+
def reset(self) -> None:
|
|
132
|
+
"""
|
|
133
|
+
Reset configuration to defaults.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
None
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
None
|
|
140
|
+
"""
|
|
141
|
+
self.config = self._default_config()
|
|
142
|
+
self.save_config()
|
|
143
|
+
self.logger.info("Configuration reset to defaults")
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Repository manager for GitHydra
|
|
3
|
+
Author: Abdulaziz Alqudimi
|
|
4
|
+
|
|
5
|
+
Main repository management class handling all Git operations.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from git import Repo, GitCommandError
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Optional, Dict, Any
|
|
11
|
+
from githydra.utils.logger import LoggingSystem
|
|
12
|
+
from githydra.core.config import ConfigurationManager
|
|
13
|
+
from githydra.core.session import SessionManager
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class RepositoryManager:
|
|
17
|
+
"""
|
|
18
|
+
Main repository manager for Git operations.
|
|
19
|
+
|
|
20
|
+
Args:
|
|
21
|
+
repo_path (str): Path to Git repository
|
|
22
|
+
config_manager (Optional[ConfigurationManager]): Configuration manager instance
|
|
23
|
+
session_manager (Optional[SessionManager]): Session manager instance
|
|
24
|
+
|
|
25
|
+
Returns:
|
|
26
|
+
RepositoryManager: Repository manager instance
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def __init__(self, repo_path: str = ".",
|
|
30
|
+
config_manager: Optional[ConfigurationManager] = None,
|
|
31
|
+
session_manager: Optional[SessionManager] = None):
|
|
32
|
+
self.repo_path = repo_path
|
|
33
|
+
self.logger = LoggingSystem()
|
|
34
|
+
self.config = config_manager or ConfigurationManager()
|
|
35
|
+
self.session = session_manager or SessionManager()
|
|
36
|
+
|
|
37
|
+
try:
|
|
38
|
+
self.repo = Repo(repo_path)
|
|
39
|
+
self.logger.info(f"Repository loaded: {self.repo.working_dir}")
|
|
40
|
+
except:
|
|
41
|
+
self.logger.warning("No repository found, initializing new repository")
|
|
42
|
+
self.repo = Repo.init(repo_path)
|
|
43
|
+
self.logger.info(f"New repository created: {self.repo.working_dir}")
|
|
44
|
+
|
|
45
|
+
def get_status(self) -> Dict[str, Any]:
|
|
46
|
+
"""
|
|
47
|
+
Get repository status.
|
|
48
|
+
|
|
49
|
+
Args:
|
|
50
|
+
None
|
|
51
|
+
|
|
52
|
+
Returns:
|
|
53
|
+
Dict[str, Any]: Status information
|
|
54
|
+
"""
|
|
55
|
+
try:
|
|
56
|
+
staged = [item.a_path for item in self.repo.index.diff('HEAD')]
|
|
57
|
+
modified = [item.a_path for item in self.repo.index.diff(None)]
|
|
58
|
+
untracked = self.repo.untracked_files
|
|
59
|
+
|
|
60
|
+
return {
|
|
61
|
+
'staged': staged,
|
|
62
|
+
'modified': modified,
|
|
63
|
+
'untracked': untracked,
|
|
64
|
+
'branch': self.repo.active_branch.name
|
|
65
|
+
}
|
|
66
|
+
except Exception as e:
|
|
67
|
+
self.logger.error(f"Failed to get status: {e}")
|
|
68
|
+
return {'staged': [], 'modified': [], 'untracked': [], 'branch': 'unknown'}
|
|
69
|
+
|
|
70
|
+
def get_current_branch(self) -> str:
|
|
71
|
+
"""
|
|
72
|
+
Get current branch name.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
None
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
str: Current branch name
|
|
79
|
+
"""
|
|
80
|
+
try:
|
|
81
|
+
return self.repo.active_branch.name
|
|
82
|
+
except:
|
|
83
|
+
return "unknown"
|
|
84
|
+
|
|
85
|
+
def is_dirty(self) -> bool:
|
|
86
|
+
"""
|
|
87
|
+
Check if repository has uncommitted changes.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
None
|
|
91
|
+
|
|
92
|
+
Returns:
|
|
93
|
+
bool: True if repository is dirty
|
|
94
|
+
"""
|
|
95
|
+
return self.repo.is_dirty()
|
|
96
|
+
|
|
97
|
+
def get_remotes(self) -> list:
|
|
98
|
+
"""
|
|
99
|
+
Get all remote repositories.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
None
|
|
103
|
+
|
|
104
|
+
Returns:
|
|
105
|
+
list: List of remote names
|
|
106
|
+
"""
|
|
107
|
+
return [remote.name for remote in self.repo.remotes]
|