gitpush-tool 0.2.2__tar.gz → 0.2.4__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.4
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.4"
@@ -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,49 @@ 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
144
+ except Exception as e:
145
+ print(f"❌ Unexpected error: {str(e)}")
146
+ return False
138
147
 
139
- def check_for_updates():
140
- """Check for newer versions on PyPI"""
148
+ def standard_git_push(commit_message, branch, remote, force=False, tags=False):
149
+ """Handle standard git push operations"""
141
150
  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
151
+ # Stage all changes
152
+ subprocess.run(["git", "add", "."], check=True)
153
+
154
+ # Commit if message provided
155
+ if commit_message:
156
+ print(f"📦 Committing: '{commit_message}'")
157
+ subprocess.run(["git", "commit", "-m", commit_message], check=True)
158
+ else:
159
+ print("ℹ️ No commit message provided - skipping commit")
160
+
161
+ # Build push command
162
+ push_cmd = ["git", "push"]
163
+ if force:
164
+ push_cmd.append("--force-with-lease")
165
+ if tags:
166
+ push_cmd.append("--tags")
167
+ if remote and branch:
168
+ push_cmd.extend([remote, branch])
169
+
170
+ print(f"🚀 Executing: {' '.join(push_cmd)}")
171
+ subprocess.run(push_cmd, check=True)
172
+ print("✅ Successfully pushed changes")
173
+ return True
174
+ except subprocess.CalledProcessError as e:
175
+ print(f"❌ Push failed: {e}")
176
+ return False
150
177
 
151
178
  def run():
152
179
  parser = argparse.ArgumentParser(
153
180
  description="🚀 Supercharged Git push tool with GitHub repo creation",
154
181
  formatter_class=argparse.RawDescriptionHelpFormatter,
155
182
  epilog="""Examples:
156
- Basic push: gitpush_tool "Commit message"
183
+ Standard push: gitpush_tool "Commit message"
157
184
  Create new repo: gitpush_tool "Initial commit" --new-repo project-name
158
185
  Private repository: gitpush_tool --new-repo private-project --private
159
186
  Force push: gitpush_tool "Fix critical bug" --force
160
- Push specific branch: gitpush_tool "Update feature" feature-branch upstream
161
187
  """
162
188
  )
163
189
  parser.add_argument("commit", nargs="?", help="Commit message")
@@ -175,7 +201,6 @@ def run():
175
201
  if args.new_repo:
176
202
  print(f"🆕 Creating repository: {args.new_repo}")
177
203
 
178
- # Check if GitHub CLI is installed
179
204
  if not check_gh_installed():
180
205
  print("❌ GitHub CLI (gh) is not installed")
181
206
  print("Please install it first:")
@@ -184,12 +209,10 @@ def run():
184
209
  print(" Linux: See https://github.com/cli/cli#installation")
185
210
  sys.exit(1)
186
211
 
187
- # Check if authenticated
188
212
  if not gh_authenticated():
189
213
  if not authenticate_with_gh():
190
214
  sys.exit(1)
191
215
 
192
- # Create repository with automatic initialization
193
216
  commit_msg = args.commit if args.commit else "Initial commit"
194
217
  if not create_with_gh_cli(
195
218
  args.new_repo,
@@ -198,44 +221,19 @@ def run():
198
221
  commit_message=commit_msg
199
222
  ):
200
223
  sys.exit(1)
201
-
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)
205
-
206
- if args.init:
224
+ elif args.init:
207
225
  if initialize_git_repository():
208
226
  create_initial_commit(args.commit or "Initial commit")
209
-
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?")
227
+ else:
228
+ # Standard git push operation
229
+ if not standard_git_push(
230
+ args.commit,
231
+ args.branch,
232
+ args.remote,
233
+ args.force,
234
+ args.tags
235
+ ):
220
236
  sys.exit(1)
221
237
 
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)
238
-
239
238
  if __name__ == "__main__":
240
- check_for_updates()
241
239
  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.4
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.4",
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