Skip to content

Commit

Permalink
refactor: update git repository upstream URL
Browse files Browse the repository at this point in the history
  • Loading branch information
BishoyHanyRaafat committed Mar 19, 2024
1 parent 4a466e5 commit f5ad592
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ Pieces autocommit tool is very powerful tool that can be used to automate commit
pip install -r requirements.txt
```

3. Stage the changes:

```bash
git add .
```

3. Run the following command
```bash
python -m autocommit
Expand All @@ -46,7 +52,7 @@ Pieces autocommit tool is very powerful tool that can be used to automate commit


## Overview
This tool is designed to automate the process of committing changes to your codebase. It not only commits your changes but also generates a commit message for you. If there is an issue related to the commit, the tool will automatically add the issue number to the commit message.
This tool is designed to automate the process of committing changes to your codebase. It not only commits your staged changes but also generates a commit message for you. If there is an issue related to the commit, the tool will automatically add the issue number to the commit message.

The tool automatically commits changes made to the codebase. This eliminates the need for manual intervention, making the process more efficient and less prone to errors.

Expand Down
13 changes: 8 additions & 5 deletions autocommit/git_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ def get_git_repo_name() -> Optional[Tuple[str]]:
A tuple containing a string representing the username and repository name.
"""
try:
# Get the remote origin URL of the git repository
repo_url = subprocess.check_output(["git", "config", "--get", "remote.origin.url"]).decode('utf-8').strip()

try:
# Get the remote origin URL of the git repository upstream url
repo_url = subprocess.check_output(["git", "config", "--get", "remote.upstream.url"]).decode('utf-8').strip()

except:
repo_url = subprocess.check_output(["git", "config", "--get", "remote.origin.url"]).decode('utf-8').strip()

# Extract the username and repository name from the URL
repo_info = repo_url.split('/')[-2:]
username, repo_name = repo_info[0], repo_info[1].replace('.git', '')
Expand All @@ -41,7 +45,7 @@ def get_current_working_changes() -> str:
A string summarizing the detailed changes in a format suitable for generating commit messages.
"""

result = subprocess.run(["git", "diff"], capture_output=True, text=True)
result = subprocess.run(["git", "diff","--staged"], capture_output=True, text=True)
if not result.stdout.strip():
raise ValueError("No changes to commit or there is no .git file initialized in the current directory")
detailed_diff = result.stdout.strip()
Expand Down Expand Up @@ -145,7 +149,6 @@ def git_commit():
if r_issue.lower() == "y":
commit_message += f" (issue: #{issue_number})"
try:
subprocess.run(["git", "add", "."], check=True)
subprocess.run(["git", "commit", "-m", commit_message], check=True)
print("Successfully committed with message:", commit_message)
except subprocess.CalledProcessError as e:
Expand Down

0 comments on commit f5ad592

Please sign in to comment.