From f5ad592390651d49068af6118bed50cd8ed30e83 Mon Sep 17 00:00:00 2001 From: BishoyHanyRaafat Date: Tue, 19 Mar 2024 14:35:58 +0200 Subject: [PATCH] refactor: update git repository upstream URL --- README.md | 8 +++++++- autocommit/git_commit.py | 13 ++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 60dd412..8948ea2 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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. diff --git a/autocommit/git_commit.py b/autocommit/git_commit.py index 7c2cc7f..d4764d6 100644 --- a/autocommit/git_commit.py +++ b/autocommit/git_commit.py @@ -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', '') @@ -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() @@ -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: