git_utils
git_read_file(repo, filepath)
¶
Read the contents of a file from a GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
str
|
The GitHub repository in the format "owner/repo" |
required |
filepath |
str
|
The file path relative to the repository root |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The contents of the file as a string |
Source code in langroid/utils/git_utils.py
get_file_list(repo, dir, pat='')
¶
Get a list of files in a specified directory of a GitHub repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
str
|
The GitHub repository in the format "owner/repo" |
required |
dir |
str
|
The directory path relative to the repository root |
required |
pat |
str
|
Optional wildcard pattern to filter file names (default: "") |
''
|
Returns:
Type | Description |
---|---|
List[str]
|
List[str]: A list of file paths in the specified directory |
Source code in langroid/utils/git_utils.py
git_init_repo(dir)
¶
Set up a Git repository in the specified directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dir |
str
|
Path to the directory where the Git repository should be initialized |
required |
Returns:
Type | Description |
---|---|
Repo | None
|
git.Repo: The initialized Git repository object |
Source code in langroid/utils/git_utils.py
git_commit_file(repo, filepath, msg)
¶
Commit a file to a Git repository.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
Repo
|
The Git repository object |
required |
filepath |
str
|
Path to the file to be committed |
required |
msg |
str
|
The commit message |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in langroid/utils/git_utils.py
git_commit_mods(repo, msg='commit all changes')
¶
Commit all modifications in the Git repository. Does not raise an error if there's nothing to commit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
Repo
|
The Git repository object |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in langroid/utils/git_utils.py
git_restore_repo(repo)
¶
Restore all unstaged, uncommitted changes in the Git repository. This function undoes any dirty files to the last commit.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
Repo
|
The Git repository object |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in langroid/utils/git_utils.py
git_restore_file(repo, file_path)
¶
Restore a specific file in the Git repository to its state in the last commit. This function undoes changes to the specified file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
Repo
|
The Git repository object |
required |
file_path |
str
|
Path to the file to be restored |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in langroid/utils/git_utils.py
git_create_checkout_branch(repo, branch)
¶
Create and checkout a new branch in the given Git repository. If the branch already exists, it will be checked out. If we're already on the specified branch, no action is taken.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
Repo
|
The Git repository object |
required |
branch |
str
|
The name of the branch to create or checkout |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in langroid/utils/git_utils.py
git_diff_file(repo, filepath)
¶
Show diffs of file between the latest commit and the previous one if any.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
repo |
Repo
|
The Git repository object |
required |
filepath |
str
|
Path to the file to be diffed |
required |
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The diff output as a string |