gitpush-tool 0.2.2__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitpush-tool
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A CLI tool to simplify Git push operations with intelligent defaults and options.
5
5
  Home-page: https://github.com/inevitablegs/gitpush
6
6
  Author: Ganesh Sonawane
@@ -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"""
@@ -42,13 +41,14 @@ def initialize_git_repository():
42
41
  """Initialize git repository if not already initialized"""
43
42
  if not os.path.exists(".git"):
44
43
  print("🛠 Initializing git repository")
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
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
52
  __pycache__/
53
53
  *.py[cod]
54
54
  *.so
@@ -72,8 +72,11 @@ Thumbs.db
72
72
  *.tmp
73
73
  *.bak
74
74
  """)
75
- print("📁 Created .gitignore file")
76
- return True
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
77
80
  return False
78
81
 
79
82
  def create_initial_commit(commit_message="Initial commit"):
@@ -92,12 +95,22 @@ def create_initial_commit(commit_message="Initial commit"):
92
95
  subprocess.run(["git", "commit", "-m", commit_message], check=True)
93
96
  return True
94
97
  return False
95
- except subprocess.CalledProcessError:
98
+ except subprocess.CalledProcessError as e:
99
+ print(f"❌ Failed to create initial commit: {e}")
96
100
  return False
97
101
 
98
102
  def create_with_gh_cli(repo_name, private=False, description="", commit_message="Initial commit"):
99
103
  """Create and push to new repository using GitHub CLI"""
100
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
+
101
114
  private_flag = "--private" if private else "--public"
102
115
  cmd = [
103
116
  "gh", "repo", "create", repo_name,
@@ -110,14 +123,7 @@ def create_with_gh_cli(repo_name, private=False, description="", commit_message=
110
123
  if description:
111
124
  cmd.extend(["--description", description])
112
125
 
113
- # Initialize Git and create initial commit if needed
114
- needs_init = initialize_git_repository()
115
- needs_commit = create_initial_commit(commit_message)
116
-
117
- if needs_init or needs_commit:
118
- print("⚡ Set up local Git repository with initial commit")
119
-
120
- # Run the create command
126
+ print("🚀 Creating repository and pushing code...")
121
127
  result = subprocess.run(cmd, check=True)
122
128
 
123
129
  if result.returncode == 0:
@@ -135,29 +141,18 @@ def create_with_gh_cli(repo_name, private=False, description="", commit_message=
135
141
  except subprocess.CalledProcessError as e:
136
142
  print(f"❌ Failed to create repository: {e.stderr if e.stderr else 'Unknown error'}")
137
143
  return False
138
-
139
- def check_for_updates():
140
- """Check for newer versions on PyPI"""
141
- try:
142
- current_version = "0.2.2"
143
- response = requests.get("https://pypi.org/pypi/gitpush-tool/json", timeout=2)
144
- latest_version = response.json()["info"]["version"]
145
- if latest_version != current_version:
146
- print(f"ℹ️ New version available: {latest_version} (you have {current_version})")
147
- print(" Run 'pip install --upgrade gitpush-tool' to update")
148
- except:
149
- pass
144
+ except Exception as e:
145
+ print(f"❌ Unexpected error: {str(e)}")
146
+ return False
150
147
 
151
148
  def run():
152
149
  parser = argparse.ArgumentParser(
153
150
  description="🚀 Supercharged Git push tool with GitHub repo creation",
154
151
  formatter_class=argparse.RawDescriptionHelpFormatter,
155
152
  epilog="""Examples:
156
- Basic push: gitpush_tool "Commit message"
157
153
  Create new repo: gitpush_tool "Initial commit" --new-repo project-name
158
154
  Private repository: gitpush_tool --new-repo private-project --private
159
155
  Force push: gitpush_tool "Fix critical bug" --force
160
- Push specific branch: gitpush_tool "Update feature" feature-branch upstream
161
156
  """
162
157
  )
163
158
  parser.add_argument("commit", nargs="?", help="Commit message")
@@ -175,7 +170,6 @@ def run():
175
170
  if args.new_repo:
176
171
  print(f"🆕 Creating repository: {args.new_repo}")
177
172
 
178
- # Check if GitHub CLI is installed
179
173
  if not check_gh_installed():
180
174
  print("❌ GitHub CLI (gh) is not installed")
181
175
  print("Please install it first:")
@@ -184,12 +178,10 @@ def run():
184
178
  print(" Linux: See https://github.com/cli/cli#installation")
185
179
  sys.exit(1)
186
180
 
187
- # Check if authenticated
188
181
  if not gh_authenticated():
189
182
  if not authenticate_with_gh():
190
183
  sys.exit(1)
191
184
 
192
- # Create repository with automatic initialization
193
185
  commit_msg = args.commit if args.commit else "Initial commit"
194
186
  if not create_with_gh_cli(
195
187
  args.new_repo,
@@ -199,43 +191,15 @@ def run():
199
191
  ):
200
192
  sys.exit(1)
201
193
 
202
- # Exit after creating new repo unless there are other operations
203
- if not args.commit and not args.force and not args.tags:
204
- sys.exit(0)
194
+ sys.exit(0)
205
195
 
206
196
  if args.init:
207
197
  if initialize_git_repository():
208
198
  create_initial_commit(args.commit or "Initial commit")
199
+ sys.exit(0)
209
200
 
210
- # Stage all changes if not in a new repo creation
211
- if not args.new_repo:
212
- subprocess.run(["git", "add", "."], check=True)
213
-
214
- if args.commit:
215
- print(f"📦 Committing: '{args.commit}'")
216
- try:
217
- subprocess.run(['git', 'commit', '-m', args.commit], check=True)
218
- except subprocess.CalledProcessError:
219
- print("❌ Commit failed - no changes to commit?")
220
- sys.exit(1)
221
-
222
- # Build push command
223
- push_cmd = ["git", "push"]
224
- if args.force:
225
- push_cmd.append("--force-with-lease")
226
- if args.tags:
227
- push_cmd.append("--tags")
228
- if args.remote and args.branch:
229
- push_cmd.extend([args.remote, args.branch])
230
-
231
- print(f"🚀 Executing: {' '.join(push_cmd)}")
232
- try:
233
- subprocess.run(push_cmd, check=True)
234
- print("✅ Successfully pushed changes")
235
- except subprocess.CalledProcessError:
236
- print("❌ Push failed")
237
- sys.exit(1)
201
+ print("ℹ️ No operation specified. Use --new-repo to create a repository or --help for options")
202
+ sys.exit(1)
238
203
 
239
204
  if __name__ == "__main__":
240
- check_for_updates()
241
205
  run()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: gitpush-tool
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: A CLI tool to simplify Git push operations with intelligent defaults and options.
5
5
  Home-page: https://github.com/inevitablegs/gitpush
6
6
  Author: Ganesh Sonawane
@@ -3,7 +3,7 @@ from pathlib import Path
3
3
 
4
4
  setup(
5
5
  name="gitpush-tool",
6
- version="0.2.2",
6
+ version="0.2.3",
7
7
  packages=find_packages(),
8
8
  install_requires=[
9
9
  'requests>=2.25.0',
@@ -1 +0,0 @@
1
- __version__ = "0.2.2"
File without changes
File without changes
File without changes
File without changes