NitorCreations / license-maintainer

Maintains license preamble in source files etc in your project
Other
16 stars 11 forks source link

doesn't work #7

Closed cyrus-smith-93 closed 7 years ago

cyrus-smith-93 commented 7 years ago

debian 9

I have made, folowing the instructions, in my custom git repo:

$ git remote add --no-tags -t hooks-only githooks-license-maintainer git@github.com:NitorCreations/license-maintainer.git

$ git fetch githooks-license-maintainer

$ git merge --allow-unrelated-histories githooks-license-maintainer/hooks-only

$ .githooks/license-maintainer/install

In my repo root I add .gitattributes:

$ cat .gitattributes
*.c    licensefile=LICENSE-soft
*.h    licensefile=LICENSE-soft
*.md    licensefile=LICENSE-docs

And, when I git commit next message appears:

Can't locate .githooks/license-maintainer/license.pm in @INC (you may need to install the .githooks::license-maintainer::license module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base) at .git/hooks/pre-commit line 22.

Can someone help to fix it?

cyrus-smith-93 commented 7 years ago

I partially fix it by replacing in .git/hooks/pre-commit

# require '.githooks/license-maintainer/license.pm';
require '/home/lx93uv/ansi-c89/.githooks/license-maintainer/license.pm';

Also, it shows

NOTE: Some files had license problems, kindly fix them in a separate commit by running:                                                                                                                

  INJECT_LICENSES=1 git commit --allow-empty -m 'Add/update licenses for all maintained files' --edit                                                                                                  

This adds/updates licenses for all maintained files, i.e.                                                                                                                                              
 - adds license to files lacking an license                                                                                                                                                            
 - adds the author (configured in the "license.author" configuration option) to                                                                                                                        
   files lacking an author                                                                                                                                                                             
 - adds missing years to existing licenses, for example if some user committed                                                                                                                         
   stuff without updating the license e.g. did not have the pre-commit hook                                                                                                                            
   installed                                                                                          

So, script doesn't insert license automatically. User must manually execute this ` INJECT_LICENSES=1 git commit --allow-empty -m 'Add/update licenses for all maintained files' --edit


command, right? Is here way to automate this?
cyrus-smith-93 commented 7 years ago

and, what is it?

$ git log --oneline
22726b2 Add/update licenses for all maintained files
be4eaf6 git license maintaining hook test
e676d78 Merge remote-tracking branch 'githooks-license-maintainer/hooks-only'
5ba86ca adds `GNU Make` build scripts, necessary books
aa2a4a5 Merge pull request #6 from lalloni/hooks-only
77e0f3a Allow author names to contain email addresses
47da504 README: git 2.9 fixes to installation instructions
01a02d4 Update README.md
7636375 Add xml support
47c3095 NOTE! Add note about directory structure update
e162019 Update README.md
77e8394 Fixes #1
558c6a0 README: Command for verifying license template configuration
ef672cd Document .gitattributes file in overview
f6ba278 Copy .gitignore from master
fbf1102 Include filename if license file cannot be read
7480d1a Install script should be executable
c50ee5f README: How to temporarily inhibit license maintenance
c29c290 README: Add license section
630c915 Implement #2: Externalize license configuration by adopting gitattributes instead.
f6fafc0 automatic install is optional
7fa964e Initial instructions

So, it's also pollutes log.

xkr47 commented 7 years ago

Hi, thanks for your report.

I have been able to reproduce your Can't locate .githooks/license-maintainer/license.pm in @INC on one machine.. I must have accidentally misused some undocumented feature/bug or something since it used to work. Will find a proper fix.

xkr47 commented 7 years ago

Yes it pollutes the log with all commits from the license-maintainer tree. I guess I could separately make releases with squashed commits as well for those who prefer. Of course you can always just copy the files into your tree (instead of using git to import them) and do the committing yourself..

xkr47 commented 7 years ago

The idea with injecting licenses only to changed files is meant so that it doesn't change the list of files included in the commit, i.e. keep the scope the same. A separate commit for license injection is imo cleaner, but you can of course use --amend or similar measures to merge them if you want.

Usually you only need to run the suggested command once or a few times (if you configure new file extensions that needs license preamble), so having it in a script isn't that helpful.. and allows you to easily edit the command / commit message as you like.

cyrus-smith-93 commented 7 years ago

Thank you for replies,

I simply looked for solution of auto-inserting license to sources.

I make hook works when change in .git/hooks/pre-commit

# require '.githooks/license-maintainer/license.pm';
require '/home/lx93uv/.../.githooks/license-maintainer/license.pm';

But I couldn't understand, why absolute path works, and relative doesn't?

xkr47 commented 7 years ago

It seems that "current directory" used to be in @INC e.g. Perl's search path before, but nowadays it isn't anymore. So I fixed it (hopefully!) by always adding "current directory" to @INC.

Please try the new version and let me know if it worked for you too.