0

I just converted my SVN repository to git. For the management I use keyword-substitution. Excerpt from the git config

smudge = "set author=`git log --pretty=format:%ae -1`; SET last_date=`git log --pretty=format:\"%ai\" -1`; SET version=`echo $lastdate | cut -d \" \" -f 1-2 | sed -e \"s/[ -:]/./g\"`; sed -e \"s/[$]Revision[$]/\\$Revision: $last_date \$/\" -e \"s/[$]Date[$]/\\$Date: $last_date \$/\" -e \"s/[$]Author[$]/\\$Author: $author \\$/\" "
clean = sed -r -e 's/([$]Revision|Date|Author)(:[^$]+ [$])/\\1$/'

Source: https://github.com/np-trivial/git-keyword-substitution

This solution should in principle also run under Windows, since I also use gnuwin32. Tools are accessible in the system environment variable. Unfortunately I always get an error message. As far as I could isolate it is because of the above code. I just have no idea what the problem is.

torek
  • 448,244
  • 59
  • 642
  • 775
ozz
  • 175
  • 1
  • 11
  • 2
    Always show the exact errors (cut and paste text if at all possible): see [ask]. It seems odd that you use `set` and then `SET`: if this is a bash or sh style command, you don't want either of those, just `author=$(...)` or ```author=`...` ...``` for instance. – torek Sep 25 '22 at 09:40

1 Answers1

1

You do not need gnuwin32.
Content filter driver would work from a regular CMD session, and would be executed with the git bash included with Git for Windows.

That means your smudge/clean scripts should be in bash.
set xx= is a BAT assignmemnt. xx=... is a bash assignment.

Try:

smudge = "author=$(git log --pretty=format:%ae -1); last_date=$(git log --pretty=format:\"%ai\" -1); version=$(echo $lastdate | cut -d \" \" -f 1-2 | sed -e \"s/[ -:]/./g\"); sed -e \"s/[$]Revision[$]/\\$Revision: $last_date \$/\" -e \"s/[$]Date[$]/\\$Date: $last_date \$/\" -e \"s/[$]Author[$]/\\$Author: $author \\$/\" "
clean = sed -r -e 's/([$]Revision|Date|Author)(:[^$]+ [$])/\\1$/'

In other words, remove the set.

However, the OP ozz confirms in the comments that SmartGit does not support content filter driver.

A simple git checkout or git switch does triggers it (successfully) in command-line though.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • SmartGit still complains " Can not run program "author=`git.. CreateProcess Error 2. File not found" – ozz Sep 25 '22 at 13:11
  • @ozz First, [replace backtick with `$(...)`](https://stackoverflow.com/a/24592916/6309). Second, debug by simplifying your smudge. Try with just `author=$(git log --pretty=format:%ae -1)`, to check if it runs. Then add other directives to your smudge, to pinpoint the issue. – VonC Sep 25 '22 at 13:45
  • @ozz Test it outside of SmartGit, with kust Git for Windows, in a CMD, using `git switch anotherBranch`: a switch to branch triggers the smudge. – VonC Sep 25 '22 at 13:48
  • it seems to be a problem with smartgit. via "git checkout " it works now. Thanks you – ozz Sep 25 '22 at 16:55
  • @ozz Great, well done! I have included your comment in the answer for more visibility. – VonC Sep 25 '22 at 20:59