Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions git_tool/__main__.py

This file was deleted.

7 changes: 5 additions & 2 deletions git_tool/ci/subcommands/feature_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
app = typer.Typer(no_args_is_help=True)


@app.command("add", help="Stage files and associate them with the provided features.", no_args_is_help=True)
@app.command(
"add",
help="Stage files and associate them with the provided features.",
no_args_is_help=True,
)
def feature_add_by_add(
feature_names: list[str] = typer.Argument(
None, help="List of feature names to associate with the staged files"
Expand Down Expand Up @@ -52,7 +56,6 @@ def feature_add_by_add(
typer.echo("No features provided.", err=True)



def stage_files(selected_files: list[str]) -> bool:
"""
Stage all selected files and return whether the staging area has changed.
Expand Down
6 changes: 4 additions & 2 deletions git_tool/ci/subcommands/feature_add_from_staged.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
app = typer.Typer()


@app.command(name="add-from-staged", help="Associate staged files with features.")
@app.command(
name="add-from-staged", help="Associate staged files with features."
)
def features_from_staging_area():
"""
Use the staged files to add feature information.
Expand Down Expand Up @@ -53,4 +55,4 @@ def read_features_from_staged(type: str = "Union") -> list[str]:
"Invalid type specified. Use 'Union' or 'Intersection'."
)

return list(combined_features)
return list(combined_features)
27 changes: 21 additions & 6 deletions git_tool/ci/subcommands/feature_blame.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

import typer
from git import Repo
from git_tool.feature_data.read_feature_data.parse_data import get_features_touched_by_commit
from git_tool.feature_data.read_feature_data.parse_data import (
get_features_touched_by_commit,
)
from git_tool.feature_data.models_and_context.repo_context import (
repo_context,
)
Expand Down Expand Up @@ -45,7 +47,9 @@ def get_line_to_blame_mapping(
return line_to_blame


def get_commit_to_features_mapping(line_to_commit: dict[int, tuple[str, str]]) -> dict[str, str]:
def get_commit_to_features_mapping(
line_to_commit: dict[int, tuple[str, str]],
) -> dict[str, str]:
"""
Returns a mapping of commit hashes to features.
"""
Expand All @@ -66,7 +70,9 @@ def get_line_to_features_mapping(
Returns a mapping of line numbers to features.
"""
# Get the commit for each line using 'git blame'
line_to_blame = get_line_to_blame_mapping(repo, file_path, start_line, end_line)
line_to_blame = get_line_to_blame_mapping(
repo, file_path, start_line, end_line
)
# for debugging: print("Step 1: ", line_to_blame)

# Get the features for each commit
Expand Down Expand Up @@ -95,19 +101,28 @@ def print_feature_blame_output(
line_to_features, line_to_blame = mappings
# Get the max width of feature strings for alignment
max_feature_width = max(
(len(line_to_features.get(commit, "UNKNOWN")) for commit in line_to_features.values()),
(
len(line_to_features.get(commit, "UNKNOWN"))
for commit in line_to_features.values()
),
default=15,
)

for i in range(start_line, end_line + 1):
line = lines[i - 1] # Adjust because list is 0-indexed, but line numbers start from 1
line = lines[
i - 1
] # Adjust because list is 0-indexed, but line numbers start from 1
commit_hash, blame_text = line_to_blame.get(i)
blame_text = blame_text.replace("(", "", 1)
feature = line_to_features.get(i, "UNKNOWN")
typer.echo(f"{feature:<15} ({commit_hash} {blame_text}")


@app.command(help="Display features associated with file lines.", no_args_is_help=True, name=None)
@app.command(
help="Display features associated with file lines.",
no_args_is_help=True,
name=None,
)
def feature_blame(
filename: str = typer.Argument(
..., help="The file to display feature blame for."
Expand Down
15 changes: 10 additions & 5 deletions git_tool/ci/subcommands/feature_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
read_staged_featureset,
reset_staged_featureset,
)
from git_tool.feature_data.models_and_context.repo_context import repo_context, sync_feature_branch
from git_tool.feature_data.models_and_context.repo_context import (
repo_context,
sync_feature_branch,
)


app = typer.Typer(
Expand All @@ -36,7 +39,10 @@ def feature_commit(
help="Manually specify feature names. Each feature-name needs to be prefixed with --features <name>\
If this option is provided, staged feature information will be ignored.",
),
upload: bool = typer.Option(True, help="Set whether feature information are also directly uploaded to remote.")
upload: bool = typer.Option(
True,
help="Set whether feature information are also directly uploaded to remote.",
),
):
"""
Associate feature information with a regular git commit.
Expand Down Expand Up @@ -76,13 +82,12 @@ def feature_commit(
# Add the fact to the metadata branch
add_fact_to_metadata_branch(fact=feature_fact, commit_ref=commit_obj)
typer.echo(f"Features {features} assigned to {commit_id}")

if upload:
sync_feature_branch()
# typer.echo("Step 4: Cleanup all information/ internal state stuff")
reset_staged_featureset()



# typer.echo("Feature commit process completed successfully.")


Expand Down
5 changes: 4 additions & 1 deletion git_tool/ci/subcommands/feature_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def print_list_w_indent(stuff: list, indent: int = 1) -> None:
typer.echo("\t" * indent + item)


app = typer.Typer(help="Displaying feature information for the entire git repo", no_args_is_help=True)
app = typer.Typer(
help="Displaying feature information for the entire git repo",
no_args_is_help=True,
)


# TODO sollte zu git feature-status
Expand Down
2 changes: 1 addition & 1 deletion git_tool/ci/subcommands/feature_info_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def all_feature_info():

def print_list_w_indent(stuff: list, indent: int = 1) -> None:
for item in stuff:
typer.echo("\t" * indent + item)
typer.echo("\t" * indent + item)
4 changes: 3 additions & 1 deletion git_tool/ci/subcommands/feature_pre_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ def feature_pre_commit():
staged_features = read_staged_featureset()

if not staged_features:
typer.echo("Warning: No features associated with the staged changes. Remember to use git feature-commit to add these information")
typer.echo(
"Warning: No features associated with the staged changes. Remember to use git feature-commit to add these information"
)
raise typer.Exit(code=0)

typer.echo("Pre-commit checks passed.")
Expand Down
3 changes: 2 additions & 1 deletion git_tool/ci/subcommands/feature_status.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections import defaultdict

import typer

from git_tool.feature_data.git_status_per_feature import (
Expand All @@ -23,7 +24,7 @@
def feature_status(
help: bool = typer.Option(
None, "--help", "-h", is_eager=True, help="Show this message and exit."
)
),
):
"""
Displays the current status of files in the working directory, showing staged, unstaged, and untracked changes along with their associated features.
Expand Down
Loading