gitpush-tool 0.2.1__tar.gz → 0.2.3__tar.gz
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.
- {gitpush_tool-0.2.1/gitpush_tool.egg-info → gitpush_tool-0.2.3}/PKG-INFO +1 -1
- gitpush_tool-0.2.3/gitpush_tool/__init__.py +1 -0
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/gitpush_tool/cli.py +85 -91
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3/gitpush_tool.egg-info}/PKG-INFO +1 -1
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/setup.py +1 -1
- gitpush_tool-0.2.1/gitpush_tool/__init__.py +0 -1
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/LICENSE +0 -0
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/MANIFEST.in +0 -0
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/README.md +0 -0
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/gitpush_tool.egg-info/SOURCES.txt +0 -0
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/gitpush_tool.egg-info/dependency_links.txt +0 -0
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/gitpush_tool.egg-info/entry_points.txt +0 -0
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/gitpush_tool.egg-info/requires.txt +0 -0
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/gitpush_tool.egg-info/top_level.txt +0 -0
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/pyproject.toml +0 -0
- {gitpush_tool-0.2.1 → gitpush_tool-0.2.3}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.3"
|
|
@@ -4,7 +4,6 @@ import argparse
|
|
|
4
4
|
import sys
|
|
5
5
|
import subprocess
|
|
6
6
|
from datetime import datetime
|
|
7
|
-
import requests
|
|
8
7
|
|
|
9
8
|
def check_gh_installed():
|
|
10
9
|
"""Check if GitHub CLI is installed"""
|
|
@@ -38,9 +37,80 @@ def authenticate_with_gh():
|
|
|
38
37
|
print("❌ GitHub CLI not found")
|
|
39
38
|
return False
|
|
40
39
|
|
|
40
|
+
def initialize_git_repository():
|
|
41
|
+
"""Initialize git repository if not already initialized"""
|
|
42
|
+
if not os.path.exists(".git"):
|
|
43
|
+
print("🛠 Initializing git repository")
|
|
44
|
+
try:
|
|
45
|
+
subprocess.run(["git", "init"], check=True)
|
|
46
|
+
subprocess.run(["git", "branch", "-M", "main"], check=True)
|
|
47
|
+
|
|
48
|
+
# Create basic .gitignore if doesn't exist
|
|
49
|
+
if not os.path.exists(".gitignore"):
|
|
50
|
+
with open(".gitignore", "w") as f:
|
|
51
|
+
f.write("""# Python
|
|
52
|
+
__pycache__/
|
|
53
|
+
*.py[cod]
|
|
54
|
+
*.so
|
|
55
|
+
.Python
|
|
56
|
+
env/
|
|
57
|
+
venv/
|
|
58
|
+
.env
|
|
59
|
+
|
|
60
|
+
# IDE
|
|
61
|
+
.vscode/
|
|
62
|
+
.idea/
|
|
63
|
+
*.swp
|
|
64
|
+
*.swo
|
|
65
|
+
|
|
66
|
+
# System
|
|
67
|
+
.DS_Store
|
|
68
|
+
Thumbs.db
|
|
69
|
+
|
|
70
|
+
# Project specific
|
|
71
|
+
*.log
|
|
72
|
+
*.tmp
|
|
73
|
+
*.bak
|
|
74
|
+
""")
|
|
75
|
+
print("📁 Created .gitignore file")
|
|
76
|
+
return True
|
|
77
|
+
except subprocess.CalledProcessError as e:
|
|
78
|
+
print(f"❌ Failed to initialize Git repository: {e}")
|
|
79
|
+
return False
|
|
80
|
+
return False
|
|
81
|
+
|
|
82
|
+
def create_initial_commit(commit_message="Initial commit"):
|
|
83
|
+
"""Create initial commit if no commits exist"""
|
|
84
|
+
try:
|
|
85
|
+
# Check if there are any commits
|
|
86
|
+
result = subprocess.run(["git", "rev-list", "--count", "HEAD"],
|
|
87
|
+
stdout=subprocess.PIPE,
|
|
88
|
+
stderr=subprocess.PIPE,
|
|
89
|
+
text=True)
|
|
90
|
+
commit_count = int(result.stdout.strip()) if result.stdout.strip().isdigit() else 0
|
|
91
|
+
|
|
92
|
+
if commit_count == 0:
|
|
93
|
+
print("📦 Creating initial commit")
|
|
94
|
+
subprocess.run(["git", "add", "."], check=True)
|
|
95
|
+
subprocess.run(["git", "commit", "-m", commit_message], check=True)
|
|
96
|
+
return True
|
|
97
|
+
return False
|
|
98
|
+
except subprocess.CalledProcessError as e:
|
|
99
|
+
print(f"❌ Failed to create initial commit: {e}")
|
|
100
|
+
return False
|
|
101
|
+
|
|
41
102
|
def create_with_gh_cli(repo_name, private=False, description="", commit_message="Initial commit"):
|
|
42
103
|
"""Create and push to new repository using GitHub CLI"""
|
|
43
104
|
try:
|
|
105
|
+
# First ensure we have a Git repository
|
|
106
|
+
if not os.path.exists(".git"):
|
|
107
|
+
if not initialize_git_repository():
|
|
108
|
+
return False
|
|
109
|
+
|
|
110
|
+
# Create initial commit if needed
|
|
111
|
+
if not create_initial_commit(commit_message):
|
|
112
|
+
print("ℹ️ Using existing commits")
|
|
113
|
+
|
|
44
114
|
private_flag = "--private" if private else "--public"
|
|
45
115
|
cmd = [
|
|
46
116
|
"gh", "repo", "create", repo_name,
|
|
@@ -53,7 +123,7 @@ def create_with_gh_cli(repo_name, private=False, description="", commit_message=
|
|
|
53
123
|
if description:
|
|
54
124
|
cmd.extend(["--description", description])
|
|
55
125
|
|
|
56
|
-
|
|
126
|
+
print("🚀 Creating repository and pushing code...")
|
|
57
127
|
result = subprocess.run(cmd, check=True)
|
|
58
128
|
|
|
59
129
|
if result.returncode == 0:
|
|
@@ -69,70 +139,20 @@ def create_with_gh_cli(repo_name, private=False, description="", commit_message=
|
|
|
69
139
|
return True
|
|
70
140
|
return False
|
|
71
141
|
except subprocess.CalledProcessError as e:
|
|
72
|
-
print(f"❌ Failed to create repository: {e.stderr}")
|
|
142
|
+
print(f"❌ Failed to create repository: {e.stderr if e.stderr else 'Unknown error'}")
|
|
143
|
+
return False
|
|
144
|
+
except Exception as e:
|
|
145
|
+
print(f"❌ Unexpected error: {str(e)}")
|
|
73
146
|
return False
|
|
74
|
-
|
|
75
|
-
def initialize_repository(remote_url=None):
|
|
76
|
-
"""Initialize git repository with sensible defaults"""
|
|
77
|
-
if not os.path.exists(".git"):
|
|
78
|
-
print("🛠 Initializing git repository")
|
|
79
|
-
subprocess.run(["git", "init"], check=True)
|
|
80
|
-
subprocess.run(["git", "branch", "-M", "main"], check=True)
|
|
81
|
-
|
|
82
|
-
if remote_url:
|
|
83
|
-
subprocess.run(["git", "remote", "add", "origin", remote_url], check=True)
|
|
84
|
-
|
|
85
|
-
# Create basic .gitignore if doesn't exist
|
|
86
|
-
if not os.path.exists(".gitignore"):
|
|
87
|
-
with open(".gitignore", "w") as f:
|
|
88
|
-
f.write("""# Python
|
|
89
|
-
__pycache__/
|
|
90
|
-
*.py[cod]
|
|
91
|
-
*.so
|
|
92
|
-
.Python
|
|
93
|
-
env/
|
|
94
|
-
venv/
|
|
95
|
-
.env
|
|
96
|
-
|
|
97
|
-
# IDE
|
|
98
|
-
.vscode/
|
|
99
|
-
.idea/
|
|
100
|
-
*.swp
|
|
101
|
-
*.swo
|
|
102
|
-
|
|
103
|
-
# System
|
|
104
|
-
.DS_Store
|
|
105
|
-
Thumbs.db
|
|
106
|
-
|
|
107
|
-
# Project specific
|
|
108
|
-
*.log
|
|
109
|
-
*.tmp
|
|
110
|
-
*.bak
|
|
111
|
-
""")
|
|
112
|
-
print("📁 Created .gitignore file")
|
|
113
|
-
|
|
114
|
-
def check_for_updates():
|
|
115
|
-
"""Check for newer versions on PyPI"""
|
|
116
|
-
try:
|
|
117
|
-
current_version = "0.2.1" # Should match your setup.py
|
|
118
|
-
response = requests.get("https://pypi.org/pypi/gitpush-tool/json", timeout=2)
|
|
119
|
-
latest_version = response.json()["info"]["version"]
|
|
120
|
-
if latest_version != current_version:
|
|
121
|
-
print(f"ℹ️ New version available: {latest_version} (you have {current_version})")
|
|
122
|
-
print(" Run 'pip install --upgrade gitpush-tool' to update")
|
|
123
|
-
except:
|
|
124
|
-
pass
|
|
125
147
|
|
|
126
148
|
def run():
|
|
127
149
|
parser = argparse.ArgumentParser(
|
|
128
150
|
description="🚀 Supercharged Git push tool with GitHub repo creation",
|
|
129
151
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
130
152
|
epilog="""Examples:
|
|
131
|
-
Basic push: gitpush_tool "Commit message"
|
|
132
153
|
Create new repo: gitpush_tool "Initial commit" --new-repo project-name
|
|
133
154
|
Private repository: gitpush_tool --new-repo private-project --private
|
|
134
155
|
Force push: gitpush_tool "Fix critical bug" --force
|
|
135
|
-
Push specific branch: gitpush_tool "Update feature" feature-branch upstream
|
|
136
156
|
"""
|
|
137
157
|
)
|
|
138
158
|
parser.add_argument("commit", nargs="?", help="Commit message")
|
|
@@ -150,7 +170,6 @@ def run():
|
|
|
150
170
|
if args.new_repo:
|
|
151
171
|
print(f"🆕 Creating repository: {args.new_repo}")
|
|
152
172
|
|
|
153
|
-
# Check if GitHub CLI is installed
|
|
154
173
|
if not check_gh_installed():
|
|
155
174
|
print("❌ GitHub CLI (gh) is not installed")
|
|
156
175
|
print("Please install it first:")
|
|
@@ -159,53 +178,28 @@ def run():
|
|
|
159
178
|
print(" Linux: See https://github.com/cli/cli#installation")
|
|
160
179
|
sys.exit(1)
|
|
161
180
|
|
|
162
|
-
# Check if authenticated
|
|
163
181
|
if not gh_authenticated():
|
|
164
182
|
if not authenticate_with_gh():
|
|
165
183
|
sys.exit(1)
|
|
166
184
|
|
|
167
|
-
|
|
185
|
+
commit_msg = args.commit if args.commit else "Initial commit"
|
|
168
186
|
if not create_with_gh_cli(
|
|
169
187
|
args.new_repo,
|
|
170
188
|
private=args.private,
|
|
171
189
|
description=args.description or "",
|
|
172
|
-
commit_message=
|
|
190
|
+
commit_message=commit_msg
|
|
173
191
|
):
|
|
174
192
|
sys.exit(1)
|
|
193
|
+
|
|
194
|
+
sys.exit(0)
|
|
175
195
|
|
|
176
196
|
if args.init:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
subprocess.run(["git", "add", "."], check=True)
|
|
197
|
+
if initialize_git_repository():
|
|
198
|
+
create_initial_commit(args.commit or "Initial commit")
|
|
199
|
+
sys.exit(0)
|
|
181
200
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
try:
|
|
185
|
-
subprocess.run(['git', 'commit', '-m', args.commit], check=True)
|
|
186
|
-
except subprocess.CalledProcessError:
|
|
187
|
-
print("❌ Commit failed")
|
|
188
|
-
sys.exit(1)
|
|
189
|
-
else:
|
|
190
|
-
print("⚠️ Skipping commit (no message provided)")
|
|
191
|
-
|
|
192
|
-
# Build push command
|
|
193
|
-
push_cmd = ["git", "push"]
|
|
194
|
-
if args.force:
|
|
195
|
-
push_cmd.append("--force-with-lease")
|
|
196
|
-
if args.tags:
|
|
197
|
-
push_cmd.append("--tags")
|
|
198
|
-
if args.remote and args.branch:
|
|
199
|
-
push_cmd.extend([args.remote, args.branch])
|
|
200
|
-
|
|
201
|
-
print(f"🚀 Executing: {' '.join(push_cmd)}")
|
|
202
|
-
try:
|
|
203
|
-
subprocess.run(push_cmd, check=True)
|
|
204
|
-
print("✅ Successfully pushed changes")
|
|
205
|
-
except subprocess.CalledProcessError:
|
|
206
|
-
print("❌ Push failed")
|
|
207
|
-
sys.exit(1)
|
|
201
|
+
print("ℹ️ No operation specified. Use --new-repo to create a repository or --help for options")
|
|
202
|
+
sys.exit(1)
|
|
208
203
|
|
|
209
204
|
if __name__ == "__main__":
|
|
210
|
-
check_for_updates()
|
|
211
205
|
run()
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.1"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|