Skip to content

Instantly share code, notes, and snippets.

@colegleason
Created July 25, 2012 21:05
Show Gist options
  • Select an option

  • Save colegleason/3178672 to your computer and use it in GitHub Desktop.

Select an option

Save colegleason/3178672 to your computer and use it in GitHub Desktop.
Show stashed changes after checkout
#!/usr/bin/env python
#
# .git/hooks/post-checkout
import sys
import subprocess
git_name = subprocess.Popen(("git","name-rev","--name-only", "HEAD"),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
branch_name = git_name.communicate()[0].strip('\n')
git_name.stdout.close()
git_stash = subprocess.Popen(("git", "stash", "list", "--grep", branch_name),
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out,err = git_stash.communicate()
if out:
print("Stashed changes on this branch:")
print(out.strip('\n'))
if err:
print(err)
@dylnuge
Copy link
Copy Markdown

dylnuge commented Jul 25, 2012

subprocess.check_output, buddy.

@dylnuge
Copy link
Copy Markdown

dylnuge commented Jul 25, 2012

But this is a really cool script :)

@colegleason
Copy link
Copy Markdown
Author

colegleason commented Jul 25, 2012 via email

@dylnuge
Copy link
Copy Markdown

dylnuge commented Jul 25, 2012

Also instead of grepping the list output, give list selective options (see man git-log).

@colegleason
Copy link
Copy Markdown
Author

like git stash list --grep ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment