Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git prompt using libgit2 (again) #55

Merged
merged 36 commits into from
Oct 30, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ca7da17
Added simple Git repository parsing code
tfpf Oct 26, 2024
4b0f479
Workflow: install libgit2 on Linux
tfpf Oct 26, 2024
6e2bf9d
Merge and rebase status
tfpf Oct 26, 2024
1d513ec
Cherry-picking and reverting statuses
tfpf Oct 26, 2024
8aabb90
Reverted workflow change
tfpf Oct 26, 2024
40c3a21
Bisecting status
tfpf Oct 26, 2024
b26338a
Full handling of (unborn) branch name, commit ID and tag
tfpf Oct 27, 2024
0ce33f4
No need to check if reference is branch
tfpf Oct 27, 2024
3cf7081
Status listing with callback
tfpf Oct 27, 2024
2c79469
Moved callback function explanation to declaration
tfpf Oct 27, 2024
7078293
Replaced state `bool`s with single `std::string`
tfpf Oct 28, 2024
0329967
Added `bare` member
tfpf Oct 28, 2024
779c8e2
Renamed `set_*` methods as `establish_*` because they are not setters
tfpf Oct 28, 2024
9b024ce
Skip ignored files in status detection
tfpf Oct 28, 2024
d34b6e4
Completed status detection code
tfpf Oct 28, 2024
1b14bf9
Use git information from libgit2 instead of `__git_ps1`
tfpf Oct 28, 2024
74ec24c
Updated Bash and Zsh to not pass `__git_ps1` output
tfpf Oct 28, 2024
29aa066
Initialise all primitive members
tfpf Oct 28, 2024
5da796e
Fixed edge case: a file can be new and modified both
tfpf Oct 28, 2024
4cdf16e
Removed static linking on Windows
tfpf Oct 28, 2024
9e84074
Renames and minor fixes
tfpf Oct 28, 2024
4fcd5a7
Moved tag detection to separate method
tfpf Oct 29, 2024
440574f
Detect annotated and unannotated tags both
tfpf Oct 29, 2024
7ee0bc5
Bit-fiddling to set dirty, staged and untracked statuses
tfpf Oct 29, 2024
11a0a93
Removed parameter names from method declarations
tfpf Oct 29, 2024
8197bf6
Merged with `main`
tfpf Oct 29, 2024
c1bd247
Updated documentation
tfpf Oct 30, 2024
32b417b
Merge branch 'libgit2-git-ps1-impl' of https://github.com/tfpf/dotfil…
tfpf Oct 30, 2024
82fd168
Added Windows workflow to build libgit2 statically
tfpf Oct 30, 2024
e6a4325
Use Git instead of GitHub CLI, which requires a token
tfpf Oct 30, 2024
783ba6d
Install to target
tfpf Oct 30, 2024
e339c64
Fixed `make` command
tfpf Oct 30, 2024
93e4ab0
Windows has `mkdir`
tfpf Oct 30, 2024
9788817
Install pkg-onfig
tfpf Oct 30, 2024
27cbf0a
Removed package workflow
tfpf Oct 30, 2024
5719a28
Removed code to load `__git_ps1` in Bash and Zsh
tfpf Oct 30, 2024
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
29 changes: 29 additions & 0 deletions custom-prompt/custom-prompt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@ class GitRepository
private:
void set_description(void);
void set_state(void);
void set_status(void);
tfpf marked this conversation as resolved.
Show resolved Hide resolved
static int compare_tag_update_description(char const* name, C::git_oid* oid, void* self_);
static int update_status(char const* path, unsigned status_flags, void* self_);
};

/******************************************************************************
Expand All @@ -208,6 +210,7 @@ GitRepository::GitRepository(void) :
this->set_description();
this->detached = C::git_repository_head_detached(this->repo);
this->set_state();
this->set_status();
}

/******************************************************************************
Expand Down Expand Up @@ -274,6 +277,15 @@ void GitRepository::set_state(void)
}
}

/******************************************************************************
* Obtain the current status of the index and working tree of the current Git
* repository.
*****************************************************************************/
void GitRepository::set_status(void)
{
C::git_status_foreach(this->repo, this->update_status, this);
}

tfpf marked this conversation as resolved.
Show resolved Hide resolved
/******************************************************************************
* Check whether the given tag matches the reference of the given
* `GitRepository` instance. If it does, update the description of the latter
Expand Down Expand Up @@ -304,6 +316,23 @@ int GitRepository::compare_tag_update_description(char const* name, C::git_oid*
return 1;
}

/******************************************************************************
* Check whether the given file is modified, staged or untracked, and update
* the corresponding members of the given `GitRepository` instance.
*
* @param path File path.
* @param status_flags Flags indicating the status of the file.
* @param self_ `GitRepository` instance whose members should be updated.
*
* @return 1 if all statuses are recorded, 0 otherwise.
*****************************************************************************/
int GitRepository::update_status(char const* path, unsigned status_flags, void* self_)
{
GitRepository* self = static_cast<GitRepository*>(self_);
LOG_DEBUG("path=%s", path);
return 0;
}

/******************************************************************************
* Provide information about the current Git repository in a manner suitable to
* display in the shell prompt.
Expand Down
Loading