Skip to content

Commit

Permalink
Fix corner cases of ASCII-only mode of status
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski committed Dec 15, 2019
1 parent f23e166 commit aa674b1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## New in git-machete 2.12.4

- fixed: remove stray ANSI escape characters in ASCII-only mode
- improved: `machete-status-branch` hook now receives `ASCII_ONLY` env var depending on whether `status` runs in ASCII-only mode
- fixed: artifact upload to Github Releases
- added: creation and upload of Debian packages to Github Releases

Expand Down
11 changes: 8 additions & 3 deletions git_machete/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1485,7 +1485,8 @@ def print_line_prefix(b_, suffix):
fp_suffix = (colored(" " + right_arrow() + " fork point ???", RED) + " commit " + short_sha(fp_sha(b)) + " found in reflog of " + fp_branches_formatted)
else:
fp_suffix = ''
print_line_prefix(b, vertical_bar() + " " + ENDC + dim(msg) + fp_suffix + "\n")
print_line_prefix(b, vertical_bar())
write_unicode(" " + dim(msg) + fp_suffix + "\n")
elbow_ascii_only = {DIM: "m-", RED: "x-", GREEN: "o-", YELLOW: "?-"}
elbow = u"└─" if not ascii_only else elbow_ascii_only[edge_color[b]]
print_line_prefix(b, elbow)
Expand All @@ -1512,7 +1513,8 @@ def print_line_prefix(b_, suffix):
hook_output = ""
if hook_executable:
debug("status()", "running machete-status-branch hook (%s) for branch %s" % (hook_path, b))
status_code, stdout, stderr = popen_cmd(hook_path, b, cwd=get_root_dir())
hook_env = dict(os.environ, ASCII_ONLY=str(ascii_only).lower())
status_code, stdout, stderr = popen_cmd(hook_path, b, cwd=get_root_dir(), env=hook_env)
if status_code == 0:
if not stdout.isspace():
hook_output = " " + stdout.rstrip()
Expand Down Expand Up @@ -1726,6 +1728,9 @@ def usage(c=None):
The standard output of this hook is displayed at the end of the line, after branch name, (optionally) custom annotation and (optionally) remote sync-ness status.
Standard error is ignored. If the hook returns a non-zero status, both stdout and stderr are ignored, and printing the status continues as usual.
Note: the hook is always invoked with 'ASCII_ONLY' variable passed into the environment.
If 'status' runs in ASCII-only mode (i.e. if '--color=auto' and stdout is not a terminal, or if '--color=never'), then 'ASCII_ONLY=true', otherwise 'ASCII_ONLY=false'.
Please see hook_samples/ directory for examples (also includes an example of using the standard git post-commit hook to 'git machete add' branches automatically).
""",
"list": """
Expand Down Expand Up @@ -1849,7 +1854,7 @@ def usage(c=None):
Options:
-l, --list-commits Additionally lists the messages of commits introduced on each branch.
--color=WHEN Colorize the output; WHEN can be 'always', 'auto', or 'never'.
--color=WHEN Colorize the output; WHEN can be 'always', 'auto' (default; i.e. only if stdout is a terminal), or 'never'.
""",
"traverse": """
Usage: git machete traverse [-l|--list-commits]
Expand Down
8 changes: 6 additions & 2 deletions hook_samples/machete-status-branch
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ submod_commit=$(git ls-tree -d "$branch" -- "$submod_rel_path" | grep -Po '(?<=1
# Check which submodule's local branches (and/or submodule's HEAD) point at submod_commit.
refs=$(git --git-dir=.git/modules/"$submod_rel_path" log --no-walk --format=%D --decorate --decorate-refs-exclude=refs/remotes/ "$submod_commit")

dim='\033[2m'
endc='\033[0m'
function ansi_esc {
[[ $ASCII_ONLY = true ]] || echo -n "$1"
}
dim=$(ansi_esc '\033[2m')
endc=$(ansi_esc '\033[0m')

echo -ne "${dim}[$(basename "$submod_rel_path") at $endc"
if [ -n "$refs" ] && [ "$refs" != HEAD ]; then
echo -n "$refs"
Expand Down

0 comments on commit aa674b1

Please sign in to comment.