Skip to content

Commit d698051

Browse files
Edward-Codegencodegen-bot
and
codegen-bot
authored
Deprecate default_branch from LocalRepoOperator (#116)
# Motivation <!-- Why is this change necessary? --> # Content <!-- Please include a summary of the change --> # Testing <!-- How was the change tested? --> # Please check the following before marking your PR as ready for review - [ ] I have added tests for my changes - [ ] I have updated the documentation or added new documentation as needed - [ ] I have read and agree to the [Contributor License Agreement](../CLA.md) Co-authored-by: codegen-bot <[email protected]>
1 parent b848bc4 commit d698051

File tree

5 files changed

+10
-15
lines changed

5 files changed

+10
-15
lines changed

src/codegen/git/repo_operator/local_repo_operator.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,17 @@ class LocalRepoOperator(RepoOperator):
2727

2828
_repo_path: str
2929
_repo_name: str
30-
_default_branch: str
3130
_git_cli: GitCLI
3231
repo_config: BaseRepoConfig
3332

3433
def __init__(
3534
self,
3635
repo_config: BaseRepoConfig,
3736
repo_path: str, # full path to the repo
38-
default_branch: str, # default branch of the repo
3937
bot_commit: bool = True,
4038
) -> None:
4139
self._repo_path = repo_path
4240
self._repo_name = os.path.basename(repo_path)
43-
self._default_branch = default_branch
4441
os.makedirs(self.repo_path, exist_ok=True)
4542
GitCLI.init(self.repo_path)
4643
super().__init__(repo_config, self.repo_path, bot_commit)
@@ -66,15 +63,15 @@ def create_from_files(cls, repo_path: str, files: dict[str, str], bot_commit: bo
6663
create_files(base_dir=repo_path, files=files)
6764

6865
# Step 2: Init git repo
69-
op = cls(repo_path=repo_path, default_branch="main", bot_commit=bot_commit, repo_config=repo_config)
66+
op = cls(repo_path=repo_path, bot_commit=bot_commit, repo_config=repo_config)
7067
if op.stage_and_commit_all_changes("[Codegen] initial commit"):
71-
op.checkout_branch(op.default_branch, create_if_missing=True)
68+
op.checkout_branch(None, create_if_missing=True)
7269
return op
7370

7471
@classmethod
75-
def create_from_commit(cls, repo_path: str, default_branch: str, commit: str, url: str) -> Self:
72+
def create_from_commit(cls, repo_path: str, commit: str, url: str) -> Self:
7673
"""Do a shallow checkout of a particular commit to get a repository from a given remote URL."""
77-
op = cls(repo_config=BaseRepoConfig(), repo_path=repo_path, default_branch=default_branch, bot_commit=False)
74+
op = cls(repo_config=BaseRepoConfig(), repo_path=repo_path, bot_commit=False)
7875
if op.get_active_branch_or_commit() != commit:
7976
op.discard_changes()
8077
op.create_remote("origin", url)
@@ -104,8 +101,7 @@ def create_from_repo(cls, repo_path: str, url: str) -> Self:
104101
remote_head = git_cli.remotes.origin.refs[git_cli.active_branch.name].commit
105102
# If up to date, use existing repo
106103
if local_head.hexsha == remote_head.hexsha:
107-
default_branch = git_cli.active_branch.name
108-
return cls(repo_config=BaseRepoConfig(), repo_path=repo_path, default_branch=default_branch, bot_commit=False)
104+
return cls(repo_config=BaseRepoConfig(), repo_path=repo_path, bot_commit=False)
109105
except Exception:
110106
# If any git operations fail, fallback to fresh clone
111107
pass
@@ -121,9 +117,8 @@ def create_from_repo(cls, repo_path: str, url: str) -> Self:
121117

122118
# Initialize with the cloned repo
123119
git_cli = GitCLI(repo_path)
124-
default_branch = git_cli.active_branch.name
125120

126-
return cls(repo_config=BaseRepoConfig(), repo_path=repo_path, default_branch=default_branch, bot_commit=False)
121+
return cls(repo_config=BaseRepoConfig(), repo_path=repo_path, bot_commit=False)
127122

128123
####################################################################################################################
129124
# PROPERTIES

src/codegen/git/repo_operator/repo_operator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def git_diff(self) -> str:
8686

8787
@property
8888
def default_branch(self) -> str:
89-
return self._default_branch
89+
return self._default_branch or self.git_cli.active_branch.name
9090

9191
@abstractmethod
9292
def codeowners_parser(self) -> CodeOwnersParser | None: ...

src/codegen/sdk/code_generation/current_code_codebase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_current_code_codebase(config: CodebaseConfig = DefaultConfig, subdirecto
3636
"""Returns a Codebase for the code that is *currently running* (i.e. the Codegen repo)"""
3737
codegen_repo_path = get_graphsitter_repo_path()
3838
logger.info(f"Creating codebase from repo at: {codegen_repo_path} with base_path {get_codegen_codebase_base_path()}")
39-
op = LocalRepoOperator(repo_path=codegen_repo_path, default_branch="develop", bot_commit=False, repo_config=BaseRepoConfig(respect_gitignore=False))
39+
op = LocalRepoOperator(repo_path=codegen_repo_path, bot_commit=False, repo_config=BaseRepoConfig(respect_gitignore=False))
4040
config = config.model_copy(update={"base_path": get_codegen_codebase_base_path()})
4141
projects = [ProjectConfig(repo_operator=op, programming_language=ProgrammingLanguage.PYTHON, subdirectories=subdirectories, base_path=get_codegen_codebase_base_path())]
4242
codebase = Codebase(projects=projects, config=config)

src/codegen/sdk/core/codebase.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def __init__(
142142
repo_path = os.path.abspath(repo_path)
143143
repo_config = BaseRepoConfig()
144144
main_project = ProjectConfig(
145-
repo_operator=LocalRepoOperator(repo_config=repo_config, repo_path=repo_path, default_branch="main"),
145+
repo_operator=LocalRepoOperator(repo_config=repo_config, repo_path=repo_path),
146146
programming_language=determine_project_language(repo_path),
147147
)
148148
projects = [main_project]

tests/shared/codemod/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def to_op(self, name: str, token: str | None) -> LocalRepoOperator:
7373
if '[credential "https://github.codegen.app"]' not in (Path.home() / ".gitconfig").read_text():
7474
os.system("gh auth login -h github.codegen.app")
7575
os.system("gh auth setup-git -h github.codegen.app")
76-
return LocalRepoOperator.create_from_commit(str(base_path), self.default_branch, self.commit, url)
76+
return LocalRepoOperator.create_from_commit(str(base_path), self.commit, url)
7777

7878

7979
@dataclass

0 commit comments

Comments
 (0)