jacinle.cli.git#

Utility functions to get git information of the current directory.

Functions

git_current_tracking_remote()

Get the current tracking remote.

git_guard([force])

A utility function to guard the current git repo.

git_recent_logs(revision_hash[, n])

Get the recent logs of the given revision hash.

git_remote_url([remote_identifier])

Get the URL of the remote.

git_revision_hash([short])

Get the current revision hash.

git_root()

Get the root directory of the git repo.

git_status_full()

Get the full status of the current git repo.

git_uncommitted_files()

Get the list of uncommitted files.

Functions

git_current_tracking_remote()[source]#

Get the current tracking remote.

Returns:

the name of the current tracking remote.

Return type:

str

git_guard(force=False)[source]#

A utility function to guard the current git repo. It will check whether there are uncommitted files.

  • When force is False, it will print a warning message including the list of uncommitted files and the diff of the uncommitted files.

  • When force is True, it will ask a confirmation from the user. If the user confirms, it will return True. Otherwise, it will terminate the program.

Parameters:

force (bool)

git_recent_logs(revision_hash, n=5)[source]#

Get the recent logs of the given revision hash.

Parameters:
  • revision_hash (str) – the revision hash.

  • n (int) – the number of logs to be returned.

Returns:

the recent logs as a single string.

Return type:

str

git_remote_url(remote_identifier=None)[source]#

Get the URL of the remote.

Parameters:

remote_identifier (str | None) – the identifier of the remote. If None, use the current tracking remote.

Returns:

the URL of the remote.

Return type:

str

git_revision_hash(short=False)[source]#

Get the current revision hash.

Parameters:

short (bool) – whether to use the short version of the hash.

Returns:

the current revision hash.

Return type:

str

git_root()[source]#

Get the root directory of the git repo.

Returns:

the root directory of the git repo.

Return type:

str

git_status_full()[source]#

Get the full status of the current git repo. This includes the content of the untracked files and the diff of the uncommitted files. Note that when the file is too large (larger than 128 kb), its content will not be shown.

Returns:

a single string containing the full status of the current git repo.

git_uncommitted_files()[source]#

Get the list of uncommitted files.

Returns:

the list of uncommitted files.

Return type:

List[str]