scripts: git: add '--no-optional-locks' option

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á <noname.nuno@gmail.com>
This commit is contained in:
Nuno Sá 2022-09-05 15:57:11 +02:00
parent 135637745d
commit e9f46f76ca

View file

@ -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"