| Age | Commit message (Collapse) | Author | Files | Lines |
|
The main git-sonar script is updated to run more portably, targeting
narrowly POSIX-compliant shells, and has been tested to be working
correctly on bash and dash.
Other platform-specific concerns have been addressed as well by updating
some aspetcts of the scripts operation. The biggest change in this
regard is made to interactions with the timestamp file used to control
git-sonar's autofetch feature.
* bashisms:
Switch to POSIX shebang line
Convert hex character literals to octal
Remove bash string indexing
Remove echo flags
Remove use of "local" keyword
Remove [[ ]] tests
Remove shell regex evaluation
Refactor autofetch logic
Refactor rc config file management
|
|
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
The use of "\xHH" characters with echo and printf is an extension to the
POSIX spec and not supported by all shells. Replace these with octal
character literals like "\000" with 3 digits per byte.
Link: https://unix.stackexchange.com/questions/627036
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
This syntax is undefined in POSIX shell. Instead, use what should be a
more robust solution, and literally strip the $separator from the
beginning of the string, rather than just hard coding a length.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
echo options are undefined in POSIX shell.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
The "local" keyword for scoping variables is undefined in POSIX shell.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
Tests using the `[[ ]]` syntax are not supported in POSIX-compliant
shell. Remove the rest of these cases which more directly translate to
standard tests. Some small cleanups are made along the way.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
Tests performed with `[[ ]]` are not supported in POSIX-compliant shell.
However, regex evaluation with the `=~` operator is a specific bashism
which has no direct counterpart in POSIX, so I wanted to handle these
cases in their own patch.
We can simply use grep to evaluate these tests instead. The same regex
syntax is supported.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
Code for handling the auto background fetch is merged down to 1
function, and various changes are made to improve portability and POSIX
compliance.
The "lastupdatetime" file now stores the unix timestamp in its content,
rather than the mtime timestamp. This will provide better platform
cross-compatibility, and allows us to drop some code which trys to
handle different styles of the stat command.
Furthermore, the path to this file (or the .git directory) is no longer
cached, since it only needs to be obtained by the script once in this
spot.
The `[ "$timestamp" -eq "$timestamp" ]` syntax is used to confirm that
the content of the "lastupdatetime" file is an integer. This will fail
on first encounter with a repository, or if migrating from the old
timestamp-based format, or if the file was just mucked with, in which
case $timestamp is forced to 0, and a fetch will very likely just occur
on the spot. This will fixup the file by writing a new timestamp out to
it.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
All commands which source content from one of the rc files are collected
together at the bottom of the script, in the portion that runs before
prompt rendering.
Attempt to source from any and all of the files that happen to exist,
instead of just taking the first that we find. This allows for
instance, the .bash rc file to provide only bash-specific additions that
are combined with variables present in .gitradarrc. However, a new
".gitsonarrc" file is now recognized as well whose use should be
preferred by new users. File load precedence is such that
".gitsonarrc", if present, has the final say on what variables to use.
To improve portability, "source" statements are converted to the
POSIX-compliant "." syntax.
As part of this code reorganization, the get_fetch_time() function is
removed - logic merged into the fetch() function.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
Clean up functions that simply run some git command and print its output
or return its exit code.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
Better match the context of surrounding "formatter" functions.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
The logic here is similar as for %{condition} rendering to yellow. The
missing remote branch is an unexpected/abnormal state and yellow has
more consistently conveyed this in the past in git-sonar.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
When both the %{condition} and %{remote} features are rendering at the
same time, the "!" looks a little out of place - as though the
checked-out branch has some issue, rather than the local repository.
Swapping their order, as well as adding a space for separation, is more
intuitive.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
The %{remote} prompt feature is updated to more closely match the
appearance of the %{local} feature. This includes defining a new blank
default master symbol.
This patch is only intended to establish new default values. The
symbols and colors involved with this feature should soon be fully
configurable.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
A previous behavior of the %{remote} prompt feature was to print
something like "git:(upstream⚡branch)" if the branch had never been
pushed to the remote. This patch addresses this case to both clean up
the prompt appearance and change the semantics of this warning.
In my own opinion, it is quite a normal workflow to be spinning off
local-only branches, whether they are short lived or not, and giving a
noisy warning that "branch" has no remote counterpart is distracting and
counter productive. However, a situation that _is worth_ warning the
user about is the case when a branch _has been pushed to a remote_ (eg:
it has a remote and merge-target configured), but this remote
counterpart branch was unexpectedly removed. This is when git-status
says "Your branch is based on ..., but the upstream is gone."
So, separate this specific warning into a new prompt feature:
%{missingups} (missing upstream), which simply shows the lightning bolt
character when a configured upstream branch is missing. Remove this
case from %{remote}, which is now quiet when the upstream is removed
(even if a remote-tracking branch is configured). This separation to a
new element makes it possible to still see this warning if opting out of
the remote-commits feature.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
When git-sonar was first forked from git-radar, effort was made to merge
the tool down to a single executable script which was installed in the
$PATH. At the time, that meant that some files were simply concatenated
together to form the 'git-sonar' script. These banner comments were
inserted to show the origin of each section of code.
Now, these comments are largely vestigial, and some work towards
refactoring the script even further has been taking place. Remove these
banner comments which are no longer serving any purpose.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
The working directory is never changed by this script, so the cached
path to the git dir should never become invalidated.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
All active code is now contained within an outer is_repo() check. This
prevents execution inside .git directories or bare git repositories.
Remove this redundant check.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
Rewrite option parsing such that all script operations are contained
within one is_repo() guard. Some bashisms are removed in the process.
Now that we check is_repo() up front, remove extra checks throughout the
script.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
Provide an additional entrypoint 'git-precheck', a new script intended
for use by other git-related scripts to determine the initial state of a
repository before continuing to do additional work.
git-sonar now leverages some of the information returned by git-precheck
to update its "is inside git repository" check, as well as provide a new
prompt string feature which visualizes on the prompt whether a merge,
rebase, etc. is in progress.
* precheck:
Add new prompt output element "condition"
Use git-precheck to determine if we are inside a repository
Add git-precheck script
|
|
Use git-precheck to determine if any ongoing git operation is in
progress and if so, mark the repository as being in a special condition.
This is made visible via a new feature in the GIT_RADAR_FORMAT prompt
string '%{condition}', which renders '!' when active.
Like most others, this element comes with its own configurable color.
By default, this is yellow, which is used for other 'conflicted' or
abnormal states.
This patch removes the unimpactful variable $output from render_prompt()
and replaces its use with $PROMPT_FORMAT - what it was initialized to.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
Use the more robust check implemented by the new git-precheck script,
instead of the previous dot_git() logic which checks for a ".git" folder
with fallback to git-rev-parse. There is still more work to be done
though in refactoring this area of the git-sonar script.
Due to the specifics of this new implementation, git-sonar will no
longer attempt to operate inside a .git directory or a bare git
repository. This makes more sense to me, since git-sonar is intended to
be an aid during active development work or branch management from
within a working tree. This also avoids some other issues and potential
edge cases within the script that fail to run properly in those
contexts.
git-precheck exits with a code of 3 or less if it successfully
determines we are inside a valid git repository working tree, so simply
assert this in the is_repo function.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
This is an alternative entrypoint primarily intended for use in other
scripts. The purpose of git-precheck is to easily determine the state
of a git repository before going on to perform additional, possibly
disruptive work.
git-precheck tries to cover as many bases as possible - odd cases like
'merge in progress', 'cherry-pick in progress', etc. By default, we
only exit success (0) if we are in a repo that is completely clean (no
file modifications or untracked files present) and has no ongoing
operation.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
The --bash/--zsh/--fish options were converted to no-op command line
flags a while back, since their behavior in git-sonar is identical.
They are merely still recognized for compatibility with git-radar.
This being the case, don't recommend their use in git-sonar's README
file.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
It is possible for git-sonar to be installed in such a way that it is
only executable by root. For example, by running `make install` after
checking out the git tree by a user with a restrictive umask value.
Use the install command in the Makefile to explicitly set the correct
mode bits of the installed git-sonar script.
Signed-off-by: Matt Hunter <m@lfurio.us>
|
|
Signed-off-by: Malfurious <m@lfurio.us>
|
|
Signed-off-by: Malfurious <m@lfurio.us>
|
|
-h or --help will now display the usage information on the command-line.
Additionally, -f is offered as a short form of --fetch. As a
consequence of this, it is no longer necessary to specify
--bash/--fish/etc. to get the prompt to render. (However, these options
will continue to be recognized by the script, for compatibility with
git-radar.)
The content of the help text is also updated for accuracy. Shell
specific examples are removed (see the README).
Signed-off-by: Malfurious <m@lfurio.us>
|
|
Some code in the main script was only serving use in the (now deleted)
tests. Remove anything from the main file with no references to it.
Signed-off-by: Malfurious <m@lfurio.us>
|
|
I don't particularly wish to maintain these tests for a few reasons:
* Many of them make assertions strictly about rendered text / UI
* Many of them test external systems and touch the disk
* There are platform-dependent details that complicate several
tests.
So, the tests are removed. Ideally, the main script is reworked into
something simple enough it doesn't necessarily warrant heavy testing.
Signed-off-by: Malfurious <m@lfurio.us>
|
|
If a custom color is used for the stash icon, git-sonar needs to reset
the color after the icon. It was using the wrong variable for this
reset.
Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
Signed-off-by: Malfurious <m@lfurio.us>
|
|
"\001" (Start of Heading) and "\002" (Start of Text) control characters
were mistakenly removed from the color config part of the main script.
Some shells (e.g. bash) struggle with line wrapping issues without
these. Bash needs them to calculate which characters are printable and
which aren't for figuring out where to linewrap.
This patch just adds them back in.
Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
Signed-off-by: Malfurious <m@lfurio.us>
|
|
The Makefile is updated to deal with the single 'git-sonar' file only,
now that the others have been merged into it.
Additionally, several issues have been fixed with the file, including:
* Now easier to override the PREFIX variable (install location)
* PWD works properly when running make with sudo
* Install now default to system-wide
* bin directory now explicitly created if it doesn't exist
A specific problem corrected by this patch is that `PREFIX=$HOME/.local
make install` on a fresh system will no longer result in the script
being copied to the _regular file_ $HOME/.local/bin, because bin did not
exist.
Signed-off-by: Malfurious <m@lfurio.us>
|
|
The script is now contained in a single file. This file will be
cleaned/refactored over time.
Signed-off-by: Malfurious <m@lfurio.us>
|
|
Some code is restructured to remove the need for this additional
entry-point.
Signed-off-by: Malfurious <m@lfurio.us>
|
|
This commit removes the differences between the supported shells and
removes the options: --bash, --fish, and --zsh.
I can not produce any problems in any of these shells using a generic
form of the text coloring (ie: the one bash was using), so for
simplicity I will opt to unify the way colors are handled and remove
knowledge of the running shell.
Something that _may_ end up being a problem is properly rendering the
prompt in different terminal emulators. If this is of concern, it will
be dealt with at a later time.
Signed-off-by: Malfurious <m@lfurio.us>
|
|
Signed-off-by: Malfurious <m@lfurio.us>
|
|
Signed-off-by: Malfurious <m@lfurio.us>
|
|
Signed-off-by: Malfurious <m@lfurio.us>
|
|
Signed-off-by: Malfurious <m@lfurio.us>
|
|
|
|
Signed-off-by: Malfurious <m@lfurio.us>
|
|
Signed-off-by: Malfurious <m@lfurio.us>
|
|
If the user's git is configured with 'pull.ff = only', these lines would
fail since the two repositories have diverged from each other. '--ff'
is added to restore the original default of allowing either a
fast-forward or recursive merge to take place. In reality, an implicit
3-way merge is being performed. All tests now pass.
Signed-off-by: Malfurious <m@lfurio.us>
|
|
Merge pending pull request #67 of upstream git-radar project from user
cbandera. They write:
This is a pull request to fix issue #38. As it turns out, some built in
commands behave differently on Mac OS X and Linux.
In order to run the tests on Linux, I have added switch statements at
some points to call the functions with the respective syntax.
Also I realized, that the tests only worked for me when I set the
following options:
git config --global push.default simple
git config --global branch.autosetuprebase never
But that's probably just because these should be the defaults. I
normally have them set to something else...
|
|
https://github.com/rholmboe/git-radar
Merge pending pull request #107 of upstream git-radar project from user
rholmboe. Note I did manually resolve a fairly trivial conflict in the
is_cwd_a_dot_git_directory() function. From the original PR:
Bug #98 wasn't really propagated correctly, you still got git-fetch bug
when you entered a sub-directory in .git. Now it's recursive, faster and
still POSIX compliant.
|
|
Merge pending pull request #111 of upstream git-radar project from user
hallzy. They write:
I came across "typechanged" the other day in my git status. It occurs
when (for example) you change a file from being a regular file, to a
symlink.
Not sure if you want this in. I am using "TC" in the terminal to show
this.
I would also like a check on the grep's in the lines that I added. I
understand that everything inside of the square brackets can be matched,
but I am unsure what letters I would also need with this.
|
|
Merge pending pull request #119 of upstream git-radar project from
user m007. They write:
This commit allows the user to define a per repository or per branch
specific configuration of which branch git-radar compares the current
branch to. If no branch is configured explicitly "origin/master" will
be used (being backwards compatible with the current behaviour).
A branch specific remote tracking branch may be configured by executing
git config --local branch."$(git rev-parse --abbrev-ref HEAD)".git-radar-tracked-remote origin/my-branch-to-compare-to
A repository specific remote tracking may be configured by executing
git config --local git-radar.tracked-remote origin/my-branch-to-compare-to
A branch specific setting will overwrite a repository specific
configuration (which will overwrite the default, i.e origin/master).
|