From 135637745daef7bd8f6f62e1a4c75aad4b0bbb41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20S=C3=A1?= Date: Mon, 5 Sep 2022 15:47:55 +0200 Subject: [PATCH 1/2] scripts: git: add option for untracked files MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default 'git status' will look for untracked files and the script will always detect that the local tree has changes if untracked files are present. That is not always optimal since sometimes we might have, for example, some custom build scripts (for some project) that is always present and we don't want the status bar to always indicate changes. Hence, add an option to disable this behavior by adding the '-uno' flag to 'git status'. The default behavior is still maintained. Signed-off-by: Nuno Sá --- INSTALL.md | 5 +++++ scripts/git.sh | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/INSTALL.md b/INSTALL.md index e1b6587..ebeae4e 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -206,6 +206,11 @@ Set symbol or message to use when the current pane has no git repo set -g @dracula-git-no-repo-message "" ``` +Hide untracked files from being displayed as local changes +```bash +# default is false +set -g @dracula-git-no-untracked-files true +``` #### weather options diff --git a/scripts/git.sh b/scripts/git.sh index 3dba4e9..5dd8a2f 100755 --- a/scripts/git.sh +++ b/scripts/git.sh @@ -7,6 +7,7 @@ IFS=' ' read -r -a hide_status <<< $(get_tmux_option "@dracula-git-disable-statu IFS=' ' read -r -a current_symbol <<< $(get_tmux_option "@dracula-git-show-current-symbol" "✓") IFS=' ' read -r -a diff_symbol <<< $(get_tmux_option "@dracula-git-show-diff-symbol" "!") IFS=' ' read -r -a no_repo_message <<< $(get_tmux_option "@dracula-git-no-repo-message" "") +IFS=' ' read -r -a no_untracked_files <<< $(get_tmux_option "@dracula-git-no-untracked-files" "false") # Get added, modified, updated and deleted files from git status getChanges() @@ -77,8 +78,9 @@ checkEmptySymbol() # check to see if the current repo is not up to date with HEAD checkForChanges() { + [ $no_untracked_files == "false" ] && no_untracked="" || no_untracked="-uno" if [ "$(checkForGitDir)" == "true" ]; then - if [ "$(git -C $path status -s)" != "" ]; then + if [ "$(git -C $path status -s $no_untracked)" != "" ]; then echo "true" else echo "false" From e9f46f76ca4eff782d3883645971585741720efb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nuno=20S=C3=A1?= Date: Mon, 5 Sep 2022 15:57:11 +0200 Subject: [PATCH 2/2] scripts: git: add '--no-optional-locks' option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit As stated in 'git status --help': "By default, git status will automatically refresh the index, updating the cached stat information from the working tree and writing out the result. Writing out the updated index is an optimization that isn’t strictly necessary (status computes the values for itself, but writing them out is just to save subsequent programs from repeating our computation). When status is run in the background, the lock held during the write may conflict with other simultaneous processes, causing them to fail. Scripts running status in the background should consider using git --no-optional-locks status (see git(1) for details)." This was actually happen during rebasing whith the following error: "error: Unable to create '/home/nsa/work/linux/.git/index.lock': File exists. Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'. Please make sure all processes are terminated then try again. If it still fails, a git process may have crashed in this repository earlier: remove the file manually to continue." This change fixes the above... Signed-off-by: Nuno Sá --- scripts/git.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/git.sh b/scripts/git.sh index 5dd8a2f..235c44e 100755 --- a/scripts/git.sh +++ b/scripts/git.sh @@ -17,7 +17,7 @@ getChanges() declare -i updated=0; declare -i deleted=0; -for i in $(git -C $path status -s) +for i in $(git -C $path --no-optional-locks status -s) do case $i in @@ -80,7 +80,7 @@ checkForChanges() { [ $no_untracked_files == "false" ] && no_untracked="" || no_untracked="-uno" if [ "$(checkForGitDir)" == "true" ]; then - if [ "$(git -C $path status -s $no_untracked)" != "" ]; then + if [ "$(git -C $path --no-optional-locks status -s $no_untracked)" != "" ]; then echo "true" else echo "false"