Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for a pre-smart-pull hook #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/commands/smart-pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
note("No tracking remote configured, assuming 'origin'") ||
'origin'

# Run smart-pull-pre-fetch hook
repo.run_hook('smart-pull-pre-fetch')

# Fetch the remote. This pulls down all new commits from the server, not just our branch,
# but generally that's a good thing. This is the only communication we need to do with the server.
repo.fetch!(tracking_remote)
Expand Down
8 changes: 8 additions & 0 deletions lib/git-smart/git_repo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ def tracking_branch
end
end

def run_hook(hook_file)
full_path = File.join(git_dir, 'hooks', hook_file)
if File.exists?(full_path)
output = SafeShell.execute(full_path)
$?.success? ? puts(output) : raise(GitSmart::UnexpectedOutput.new(output))
end
end

def fetch!(remote)
git!('fetch', remote)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/smart-pull_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ def remote_dir; WORKING_DIR + '/remote'; end
out.should report("Already up-to-date")
end

context "with a smart-pull-pre-fetch hook" do
before :each do
%x[
cd #{local_dir}
printf '#!/bin/bash\n\necho running hook...done\n' > .git/hooks/smart-pull-pre-fetch
chmod 755 .git/hooks/smart-pull-pre-fetch
]
end

it "should run the hook" do
out = run_command(local_dir, 'smart-pull')
out.should report("running hook...done")
end
end

context "with only local changes" do
before :each do
%x[
Expand Down