func NewFromOSFileMode(m os.FileMode) (FileMode, error) {
	if m.IsRegular() {
		if isSetTemporary(m) {
			return Empty, fmt.Errorf("no equivalent git mode for %s", m)
		}
		if isSetCharDevice(m) {
			return Empty, fmt.Errorf("no equivalent git mode for %s", m)
		}
		if isSetUserExecutable(m) {
			return Executable, nil
		}
		return Regular, nil
	}
	if m.IsDir() {
		return Dir, nil
	}
	if isSetSymLink(m) {
		return Symlink, nil
	}
	return Empty, fmt.Errorf("no equivalent git mode for %s", m)
}
NewFromOSFileMode returns the FileMode used by git to represent
the provided file system modes and a nil error on success.  If the
file system mode cannot be mapped to any valid git mode (as with
sockets or named pipes), it will return Empty and an error.

Note that some git modes cannot be generated from os.FileModes, like
Deprecated and Submodule; while Empty will be returned, along with an
error, only when the method fails.
package filemode
import (
	"encoding/binary"
	"fmt"
	"os"
	"strconv"
)
type FileMode uint32
const (
	Empty FileMode = 0
	Dir FileMode = 0040000
	Regular FileMode = 0100644
	Deprecated FileMode = 0100664
	Executable FileMode = 0100755
	Symlink FileMode = 0120000
	Submodule FileMode = 0160000
)
func New(s string) (FileMode, error) {
	n, err := strconv.ParseUint(s, 8, 32)
	if err != nil {
		return Empty, err
	}
	return FileMode(n), nil
}