pre-commit hook
This commit is contained in:
parent
3281a1cb19
commit
563484e135
6 changed files with 55 additions and 15 deletions
20
Commands.hs
20
Commands.hs
|
@ -68,7 +68,7 @@ doSubCmd cmdname start param = do
|
|||
{- A subcommand can broadly want one of several kinds of input parameters.
|
||||
- This allows a first stage of filtering before starting a subcommand. -}
|
||||
data SubCmdWants = FilesInGit | FilesNotInGit | FilesMissing
|
||||
| Description | Keys | Tempfile
|
||||
| Description | Keys | Tempfile | FilesToBeCommitted
|
||||
|
||||
data SubCommand = Command {
|
||||
subcmdname :: String,
|
||||
|
@ -91,7 +91,9 @@ subCmds = [
|
|||
, (Command "unannex" unannexStart FilesInGit
|
||||
"undo accidential add command")
|
||||
, (Command "fix" fixStart FilesInGit
|
||||
"fix up files' symlinks to point to annexed content")
|
||||
"fix up symlinks to point to annexed content")
|
||||
, (Command "pre-commit" fixStart FilesToBeCommitted
|
||||
"fix up symlinks before they are committed")
|
||||
, (Command "fromkey" fromKeyStart FilesMissing
|
||||
"adds a file using a specific key")
|
||||
, (Command "dropkey" dropKeyStart Keys
|
||||
|
@ -130,7 +132,7 @@ usage = usageInfo header options ++ "\nSubcommands:\n" ++ cmddescs
|
|||
cmddescs = unlines $ map (\c -> indent $ showcmd c) subCmds
|
||||
showcmd c =
|
||||
(subcmdname c) ++
|
||||
(pad 10 (subcmdname c)) ++
|
||||
(pad 11 (subcmdname c)) ++
|
||||
(descWanted (subcmdwants c)) ++
|
||||
(pad 13 (descWanted (subcmdwants c))) ++
|
||||
(subcmddesc c)
|
||||
|
@ -161,6 +163,17 @@ findWanted FilesMissing params repo = do
|
|||
if (e) then return False else return True
|
||||
findWanted Description params _ = do
|
||||
return $ [unwords params]
|
||||
findWanted FilesToBeCommitted params repo = do
|
||||
files <- mapM gitcached params
|
||||
return $ foldl (++) [] files
|
||||
where
|
||||
gitcached p = do
|
||||
-- ask git for files staged for commit that
|
||||
-- are being added, moved, or changed (but not deleted)
|
||||
fs0 <- Git.pipeRead repo ["diff", "--cached",
|
||||
"--name-only", "--diff-filter=ACMRT",
|
||||
"-z", "HEAD", p]
|
||||
return $ filter (not . null) $ split "\0" fs0
|
||||
findWanted _ params _ = return params
|
||||
|
||||
{- Parses command line and returns two lists of actions to be
|
||||
|
@ -360,6 +373,7 @@ initPerform description = do
|
|||
u <- getUUID g
|
||||
describeUUID u description
|
||||
liftIO $ gitAttributes g
|
||||
liftIO $ gitPreCommitHook g
|
||||
return $ Just $ initCleanup
|
||||
initCleanup :: Annex Bool
|
||||
initCleanup = do
|
||||
|
|
15
Core.hs
15
Core.hs
|
@ -73,6 +73,21 @@ gitAttributes repo = do
|
|||
Git.run repo ["commit", "-m", "git-annex setup",
|
||||
attributes]
|
||||
|
||||
{- set up a git pre-commit hook, if one is not already present -}
|
||||
gitPreCommitHook :: Git.Repo -> IO ()
|
||||
gitPreCommitHook repo = do
|
||||
let hook = (Git.workTree repo) ++ "/" ++ (Git.dir repo) ++
|
||||
"/hooks/pre-commit"
|
||||
exists <- doesFileExist hook
|
||||
if (exists)
|
||||
then putStrLn $ "pre-commit hook (" ++ hook ++ ") already exists, not configuring"
|
||||
else do
|
||||
writeFile hook $ "#!/bin/sh\n" ++
|
||||
"# automatically configured by git-annex\n" ++
|
||||
"git annex pre-commit .\n"
|
||||
p <- getPermissions hook
|
||||
setPermissions hook $ p {executable = True}
|
||||
|
||||
{- Checks if a given key is currently present in the annexLocation.
|
||||
-
|
||||
- This can be run against a remote repository to check the key there. -}
|
||||
|
|
3
debian/changelog
vendored
3
debian/changelog
vendored
|
@ -4,6 +4,9 @@ git-annex (0.02) UNRELEASED; urgency=low
|
|||
file content when dropping files.
|
||||
* New move subcommand, that can move files from or to a remote.
|
||||
* New fromkey subcommand, for registering urls, etc.
|
||||
* git-annex init will now set up a pre-commit hook that fixes up symlinks
|
||||
before they are committed, to ensure that moving symlinks around does not
|
||||
break them.
|
||||
* Add remote.annex-ignore git config setting to allow completly disabling
|
||||
a given remote.
|
||||
* --from/--to can be used to control the remote repository that git-annex
|
||||
|
|
|
@ -107,9 +107,13 @@ Many git-annex subcommands will stage changes for later `git commit` by you.
|
|||
Fixes up symlinks that have become broken to again point to annexed content.
|
||||
This is useful to run if you have been moving the symlinks around.
|
||||
|
||||
You do not normally need to run this by hand since `git-annex init`
|
||||
installs a pre-commit hook that automatically fixes up symlinks when
|
||||
they are committed.
|
||||
* pre-commit [path ...]
|
||||
|
||||
Fixes up symlinks that are staged as part of a commit, to ensure they
|
||||
point to annexed content.
|
||||
|
||||
This is meant to be called from git's pre-commit hook. `git annex init`
|
||||
automatically creates a pre-commit hook using this.
|
||||
|
||||
* fromkey file
|
||||
|
||||
|
@ -202,7 +206,7 @@ decscriptions. You may edit it.
|
|||
`.git-annex/*.log` is where git-annex records its content tracking
|
||||
information. These files should be committed to git.
|
||||
|
||||
`.git-annex/.gitattributes` is configured to use git's union merge driver
|
||||
`.gitattributes` is configured to use git's union merge driver
|
||||
to avoid conflicts when merging files in the `.git-annex` directory.
|
||||
|
||||
# AUTHOR
|
||||
|
|
|
@ -10,3 +10,5 @@ up.
|
|||
back to git-annex. If you want to have your own shell script in the post-commit
|
||||
hook, just make it call `git annex` with no parameters. git-annex will detect
|
||||
when it's run from a git hook and do the necessary fixups.
|
||||
|
||||
[[done]]
|
||||
|
|
|
@ -43,23 +43,25 @@ if you are using a centralized bare repository.
|
|||
add debian.iso ok
|
||||
# git commit -a -m added
|
||||
|
||||
Notice you commit at the end, this checks in git-annex's record of the
|
||||
files but not their actual, large, content.
|
||||
When you add a file to the annex and commit it, only a symlink to
|
||||
the annexed content is committed. The content itself is stored in
|
||||
git-annex's backend.
|
||||
|
||||
## renaming files
|
||||
|
||||
# cd ~/annex
|
||||
# git mv big_file my_cool_big_file
|
||||
# mkdir iso
|
||||
# git mv debian.iso iso
|
||||
# git annex fix .
|
||||
fix iso/debian.iso ok
|
||||
# git mv debian.iso iso/
|
||||
# git commit -m moved
|
||||
|
||||
You can use any normal git operations to move files around, or even
|
||||
make copies or delete them. `git-annex fix` needs to be run if a file
|
||||
is moved into a different directory, in order to fix up the symlink
|
||||
pointing to the file's content.
|
||||
make copies or delete them.
|
||||
|
||||
Notice that, since annexed files are represented by symlinks,
|
||||
the symlink will break when the file is moved into a subdirectory.
|
||||
But, git-annex will fix this up for you when you commit --
|
||||
it has a pre-commit hook that watches for and corrects broken symlinks.
|
||||
|
||||
## getting file content
|
||||
|
||||
|
|
Loading…
Reference in a new issue