Skip to main content
added 21 characters in body
Source Link
Rudi Kershaw
  • 13k
  • 7
  • 56
  • 80

As of Java 11, you can now run un-compiled main class files using the java command.

$ java Hook.java

If you are using a Unix based operating system (MacOS or Linux for example), you can strip off the .java and add a shebang to the top line like so:

#!/your/path/to/bin/java --source 11
public class Hook {
    public static void main(String[] args) {
        System.out.println("No committing please.");
        System.exit(1);
    }
} 

then you can simply execute it the same way you would with any other script file.

$ ./Hook

If you rename the file pre-commit, and then move it into your .git/hooks directory, you now have a working Java Git Hook.

Note: You may be able to get this to work on Windows using Cygwin or Git Bash or similar terminal emulators. However, shebangs do not handle spaces very well so you may need to create. I tested that this works by moving a simlink or similar for your Java executablecopy of java into a directory without spaces and it works fine.

As of Java 11, you can now run un-compiled main class files using the java command.

$ java Hook.java

If you are using a Unix based operating system (MacOS or Linux for example), you can strip off the .java and add a shebang to the top line like so:

#!/your/path/to/bin/java --source 11
public class Hook {
    public static void main(String[] args) {
        System.out.println("No committing please.");
        System.exit(1);
    }
} 

then you can simply execute it the same way you would with any other script file.

$ ./Hook

If you rename the file pre-commit, and then move it into your .git/hooks directory, you now have a working Java Git Hook.

Note: You may be able to get this to work on Windows using Cygwin or Git Bash or similar terminal emulators. However, shebangs do not handle spaces very well so you may need to create a simlink or similar for your Java executable.

As of Java 11, you can now run un-compiled main class files using the java command.

$ java Hook.java

If you are using a Unix based operating system (MacOS or Linux for example), you can strip off the .java and add a shebang to the top line like so:

#!/your/path/to/bin/java --source 11
public class Hook {
    public static void main(String[] args) {
        System.out.println("No committing please.");
        System.exit(1);
    }
} 

then you can simply execute it the same way you would with any other script file.

$ ./Hook

If you rename the file pre-commit, and then move it into your .git/hooks directory, you now have a working Java Git Hook.

Note: You may be able to get this to work on Windows using Cygwin or Git Bash or similar terminal emulators. However, shebangs do not handle spaces well. I tested that this works by moving a copy of java into a directory without spaces and it works fine.

added 245 characters in body
Source Link
Rudi Kershaw
  • 13k
  • 7
  • 56
  • 80

As of Java 11, you can now run un-compiled main class files using the java command.

$ java Hook.java

If you are using a Unix based operating system (MacOS or Linux for example), you can strip off the .java and add a shebang to the top line like so:

#!/your/path/to/bin/java --source 11
public class Hook {
    public static void main(String[] args) {
        System.out.println("No committing please.");
        System.exit(1);
    }
} 

then you can simply execute it the same way you would with any other script file.

$ ./Hook

If you rename the file pre-commit, and then move it into your .git/hooks directory, you now have a working Java Git Hook.

Note: You may be able to get this to work on Windows using Cygwin or Git Bash or similar terminal emulators. However, shebangs do not handle spaces very well so you may need to create a simlink or similar for your Java executable.

As of Java 11, you can now run un-compiled main class files using the java command.

$ java Hook.java

If you are using a Unix based operating system (MacOS or Linux for example), you can strip off the .java and add a shebang to the top line like so:

#!/your/path/to/bin/java --source 11
public class Hook {
    public static void main(String[] args) {
        System.out.println("No committing please.");
        System.exit(1);
    }
} 

then you can simply execute it the same way you would with any other script file.

$ ./Hook

If you rename the file pre-commit, and then move it into your .git/hooks directory, you now have a working Java Git Hook.

As of Java 11, you can now run un-compiled main class files using the java command.

$ java Hook.java

If you are using a Unix based operating system (MacOS or Linux for example), you can strip off the .java and add a shebang to the top line like so:

#!/your/path/to/bin/java --source 11
public class Hook {
    public static void main(String[] args) {
        System.out.println("No committing please.");
        System.exit(1);
    }
} 

then you can simply execute it the same way you would with any other script file.

$ ./Hook

If you rename the file pre-commit, and then move it into your .git/hooks directory, you now have a working Java Git Hook.

Note: You may be able to get this to work on Windows using Cygwin or Git Bash or similar terminal emulators. However, shebangs do not handle spaces very well so you may need to create a simlink or similar for your Java executable.

added 78 characters in body
Source Link
Rudi Kershaw
  • 13k
  • 7
  • 56
  • 80

As of Java 11, you can now run un-compiled main class files using the java command.

$ java Hook.java

If you are using a Unix based operating system (MacOS or Linux for example), you can strip off the .java and add a shebang to the top line like so:

#!/your/path/to/bin/java --source 11
public class Hook {
    public static void main(String[] args) {
        System.out.println("No committing please.");
        System.exit(1);
    }
} 

then you can simply execute it the same way you would with any other script file.

$ ./Hook

If you rename the file pre-commit, and then move it into your .git/hooks directory, you now have a working Java Git Hook.

As of Java 11, you can now run un-compiled main class files using the java command.

$ java Hook.java

If you strip off the .java and add a shebang to the top line like so:

#!/your/path/to/bin/java --source 11
public class Hook {
    public static void main(String[] args) {
        System.out.println("No committing please.");
        System.exit(1);
    }
} 

then you can simply execute it the same way you would with any other script file.

$ ./Hook

If you rename the file pre-commit, and then move it into your .git/hooks directory, you now have a working Java Git Hook.

As of Java 11, you can now run un-compiled main class files using the java command.

$ java Hook.java

If you are using a Unix based operating system (MacOS or Linux for example), you can strip off the .java and add a shebang to the top line like so:

#!/your/path/to/bin/java --source 11
public class Hook {
    public static void main(String[] args) {
        System.out.println("No committing please.");
        System.exit(1);
    }
} 

then you can simply execute it the same way you would with any other script file.

$ ./Hook

If you rename the file pre-commit, and then move it into your .git/hooks directory, you now have a working Java Git Hook.

deleted 8 characters in body
Source Link
Rudi Kershaw
  • 13k
  • 7
  • 56
  • 80
Loading
Source Link
Rudi Kershaw
  • 13k
  • 7
  • 56
  • 80
Loading