awacke1 commited on
Commit
6b91c54
·
verified ·
1 Parent(s): 5525475

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -28,13 +28,31 @@ def create_repo(g, repo_name):
28
 
29
  def push_to_github(local_path, repo, github_token):
30
  repo_url = f"https://{github_token}@github.com/{repo.full_name}.git"
31
- repo = Repo(local_path)
32
- if 'origin' in [remote.name for remote in repo.remotes]:
33
- origin = repo.remote('origin')
 
34
  origin.set_url(repo_url)
35
  else:
36
- origin = repo.create_remote('origin', repo_url)
37
- origin.push(refspec='{}:{}'.format('master', 'master'))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  def main():
40
  st.title("GitHub Repository Cloner and Uploader")
 
28
 
29
  def push_to_github(local_path, repo, github_token):
30
  repo_url = f"https://{github_token}@github.com/{repo.full_name}.git"
31
+ local_repo = Repo(local_path)
32
+
33
+ if 'origin' in [remote.name for remote in local_repo.remotes]:
34
+ origin = local_repo.remote('origin')
35
  origin.set_url(repo_url)
36
  else:
37
+ origin = local_repo.create_remote('origin', repo_url)
38
+
39
+ # Determine the current branch name
40
+ if not local_repo.heads:
41
+ # If the repo is empty, create and checkout a new branch
42
+ local_repo.git.checkout('-b', 'main')
43
+ current_branch = 'main'
44
+ else:
45
+ current_branch = local_repo.active_branch.name
46
+
47
+ # Stage all files
48
+ local_repo.git.add(A=True)
49
+
50
+ # Commit changes if there are any
51
+ if local_repo.is_dirty():
52
+ local_repo.git.commit('-m', 'Initial commit')
53
+
54
+ # Push to the current branch
55
+ origin.push(refspec=f'{current_branch}:{current_branch}')
56
 
57
  def main():
58
  st.title("GitHub Repository Cloner and Uploader")