#1024536 git-crecord: fails on committing/stagin

Package:
git-crecord
Source:
git-crecord
Submitter:
Christoph Anton Mitterer
Date:
2022-11-25 14:00:03 UTC
Severity:
important
#1024536#5
Date:
2022-11-21 04:09:14 UTC
From:
To:
Hey.

I wanted to selectively stage (or commit) just two lines.
In both cases it fails with the same error:
$ git crecord
error: patch fragment without header at line 16: @@ -171,8 +171,8 @@ while [ "$#" -ge 1 ]; do
On branch improve-ssh_filter_btrbk.sh
Your branch is ahead of 'origin/improve-ssh_filter_btrbk.sh' by 2 commits.
  (use "git push" to publish your local commits)

nothing to commit, working tree clean
abort: commit failed: git exited with status 1

Any ideas?

Thanks,
Chris.

#1024536#10
Date:
2022-11-21 07:42:28 UTC
From:
To:
Hi,
1) Try the latest Git version
2) If it still fails, run with --debug, it’s going to print the patch
3) If possible, send me your working tree so that I can try it out

#1024536#15
Date:
2022-11-21 07:42:28 UTC
From:
To:
Hi,
1) Try the latest Git version
2) If it still fails, run with --debug, it’s going to print the patch
3) If possible, send me your working tree so that I can try it out

#1024536#20
Date:
2022-11-25 01:19:43 UTC
From:
To:
Hey Andrej

That's a bit difficult right now in my setup.


Could you possibly try this:

$ git init foo
Initialized empty Git repository in /home/calestyo/foo/.git/
$ cd foo/

$ touch bar
$ git add bar
$ git commit -m 'foo'
[master (root-commit) 157defb] foo
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 bar
$ printf 'a\nb\nc\n' >| bar

$ git crecord

Now here, I first unselect all, and then select only one single line,
e.g. the "b" line, like so:
[~]    diff --git a/bar b/bar
       index e69de29..de98044 100644
       1 hunks, 3 lines changed

   [~]     @@ -0,0 +1,3 @@
      [ ]  +a
      [x]  +b
      [ ]  +c

if I now "c" or "s", I get:
error: corrupt patch at line 9
On branch master
nothing to commit, working tree clean
abort: commit failed: git exited with status 1


In principle it's the same as what I did with the other repo, but maybe
that's another issue, though... cause the error message is different.


Thanks,
Chris.

#1024536#25
Date:
2022-11-25 06:39:29 UTC
From:
To:
Hi,

I’ve just realised my suggestion could be misread — I didn’t mean the latest version of Git, but the latest Git commit of git-crecord itself :)

#1024536#30
Date:
2022-11-25 06:42:57 UTC
From:
To:
Hi,

I’ve just run those commands, and it worked without an error. Given that I use git-crecord daily, I’d have caught the breakage this basic — are you sure it’s not something with your gitconfig?

Also, can you please try --debug?

#1024536#35
Date:
2022-11-25 13:40:54 UTC
From:
To:
Hmm I just tried with moving my ~/.config/git out of the way, but same
error as with:
$ git crecord --debug
backup 'bar' as '/home/calestyo/foo/.git/record-backups/bar.1hhsrizs'
applying patch
diff --git a/bar b/bar
index e69de29..de98044 100644
--- a/bar
+++ b/bar
@@ -0,0 +1,1 @@
 a
+b
 c

error: corrupt patch at line 9
On branch master
nothing to commit, working tree clean
restoring '/home/calestyo/foo/.git/record-backups/bar.1hhsrizs' to
'bar'
abort: commit failed: git exited with status 1


I had /etc/gitconfig but that only contains:
[safe]
        bareRepository = explicit


Thanks,
Chris.

#1024536#40
Date:
2022-11-25 13:57:09 UTC
From:
To:
Hey again.

I think I also managed to reproduce the first error:

$ git clone git@github.com:calestyo/btrbk.git
$ cd btrbk
$ git checkout improve-ssh_filter_btrbk.sh


$ git rebase --interactive 53b3290e14ea9c8df6288bec981d8b28655c8fa7

This shows:
pick 9819fdc ssh_filter_btrbk.sh: convert to POSIX sh
pick 3d87f27 ssh_filter_btrbk.sh: use printf instead of echo
pick 2b53311 ssh_filter_btrbk.sh: set only needed directories in PATH
pick ec8e7a1 ssh_filter_btrbk.sh: use more common exit statuses
pick 0bd7374 ssh_filter_btrbk.sh: replace OpenSSH’s deprecated SSH_CLIENT
pick 7c77f0a ssh_filter_btrbk.sh: minor improvements
pick d3126c7 ssh_filter_btrbk.sh: further harden the shell execution environment
pick 7729be4 ssh_filter_btrbk.sh: properly normalise pathnames
pick 016e945 ssh_filter_btrbk.sh: forbid non-absolute pathnames to --restrict-path

Now delete all lines except for the first:
pick 9819fdc ssh_filter_btrbk.sh: convert to POSIX sh

in order to get rid of all those commits.


Then apply the attached patch (simulating the content that I had
changed) with some of the next upcoming commits:

$ patch < changes.patch


Then:
$ git crecord

and only select the "printf" lines, i.e.:
[~]    diff --git a/ssh_filter_btrbk.sh b/ssh_filter_btrbk.sh
       index 262cbbb..21074ae 100755
       3 hunks, 4 lines changed

   [ ]     @@ -3,7 +3,7 @@
            set -e
            set -u

      [ ]  -export PATH=/sbin:/bin:/usr/sbin:/usr/bin
      [ ]  +export PATH='/usr/bin:/bin'

            enable_log=
            restrict_path_list=

   [~]     @@ -41,8 +41,8 @@ reject_and_die()
            {
                local reason="$1"
                log_cmd 'auth.err' 'btrbk REJECT' "$reason"
      [ ]  -    echo "ERROR: ssh_filter_btrbk.sh: ssh command rejected: $reason: $SSH_ORIGINAL_COMMAND" 1>&2
      [ ]  -    exit 255
      [x]  +    printf 'ERROR: ssh_filter_btrbk.sh: ssh command rejected: %s: %s\n' "$reason" "$SSH_ORIGINAL_COMMAND" 1>&2
      [ ]  +    exit 1
            }

            run_cmd()

   [~]     @@ -171,7 +171,7 @@ while [ "$#" -ge 1 ]; do
                      ;;

                  *)
      [ ]  -          echo "ERROR: ssh_filter_btrbk.sh: failed to parse command line option: $key" 1>&2
      [x]  +          printf 'ERROR: ssh_filter_btrbk.sh: failed to parse command line option: %s\n' "$key" 1>&2
                      exit 255
                      ;;
                esac


Now "c", causes:
error: patch fragment without header at line 16: @@ -171,7 +171,8 @@
while [ "$#" -ge 1 ]; do
On branch improve-ssh_filter_btrbk.sh
Your branch is behind 'origin/improve-ssh_filter_btrbk.sh' by 8
commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	changes.patch

nothing added to commit but untracked files present (use "git add" to
track)
abort: commit failed: git exited with status 1


The same with --debug:
$ git crecord --debug
backup 'ssh_filter_btrbk.sh' as '/home/calestyo/foo/z/btrbk/.git/record-backups/ssh_filter_btrbk.sh.gu99sc7q'
applying patch
diff --git a/ssh_filter_btrbk.sh b/ssh_filter_btrbk.sh
index 262cbbb..21074ae 100755
--- a/ssh_filter_btrbk.sh
+++ b/ssh_filter_btrbk.sh
@@ -41,8 +41,9 @@ reject_and_die()
 {
     local reason="$1"
     log_cmd 'auth.err' 'btrbk REJECT' "$reason"
     echo "ERROR: ssh_filter_btrbk.sh: ssh command rejected: $reason: $SSH_ORIGINAL_COMMAND" 1>&2
     exit 255
+    printf 'ERROR: ssh_filter_btrbk.sh: ssh command rejected: %s: %s\n' "$reason" "$SSH_ORIGINAL_COMMAND" 1>&2
     exit 1
 }

 run_cmd()
@@ -171,7 +171,8 @@ while [ "$#" -ge 1 ]; do
           ;;

       *)
           echo "ERROR: ssh_filter_btrbk.sh: failed to parse command line option: $key" 1>&2
+          printf 'ERROR: ssh_filter_btrbk.sh: failed to parse command line option: %s\n' "$key" 1>&2
           exit 255
           ;;
     esac

error: patch fragment without header at line 16: @@ -171,7 +171,8 @@ while [ "$#" -ge 1 ]; do
On branch improve-ssh_filter_btrbk.sh
Your branch is behind 'origin/improve-ssh_filter_btrbk.sh' by 8 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	changes.patch

nothing added to commit but untracked files present (use "git add" to track)
restoring '/home/calestyo/foo/z/btrbk/.git/record-backups/ssh_filter_btrbk.sh.gu99sc7q' to 'ssh_filter_btrbk.sh'
abort: commit failed: git exited with status 1



Thanks,
Chris.

PS & offtopic:

Is "s" (for staging) supposed to work in the current Debian sid
version? And is bash completion supposed to work (i.e. $ git cre<tab>)?