Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7d0d33d32b | |||
| b2fd270558 | |||
| 3d7177e84c | |||
| 8bbe2a7d49 | |||
| 136a777d73 | |||
| 9dd178ded8 | |||
| 6ad55433df | |||
| cf050df1f6 | |||
| 074154e726 | |||
| 900e9120b5 | |||
| 8b0bc89eb8 |
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 Ivan Malopinsky
|
||||
Copyright (c) 2017-2020 Ivan Malopinsky
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
@@ -23,7 +23,7 @@ DESCRIPTION
|
||||
- prune remote branches
|
||||
|
||||
git-fresh will ignore any branches listed in a .freshignore file.
|
||||
.freshignore should contain branch names you would like to ignore
|
||||
freshignore should contain branch names you would like to ignore
|
||||
on separate lines. The file can exist in the current Git repo
|
||||
or in the home directory, i.e. ~/.freshignore.
|
||||
|
||||
@@ -106,7 +106,7 @@ while getopts ":fmrtslRWSTv" opt; do
|
||||
TEST=true
|
||||
;;
|
||||
v)
|
||||
VERSION=1.12.0
|
||||
VERSION=1.12.1
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
@@ -159,17 +159,42 @@ fi
|
||||
ERR="could not get top-level-directory"
|
||||
TOP_LEVEL_DIRECTORY=$(git rev-parse --show-toplevel)
|
||||
REMOTE=${1:-origin}
|
||||
ROOT=${2:-master}
|
||||
|
||||
# todo: remove this code since it's still possible to get a corrupt ref on macOS
|
||||
if [[ $(ls -1 "$TOP_LEVEL_DIRECTORY/.git/refs/heads" | wc -l | xargs) -eq "0" ]]; then
|
||||
if git rev-parse --verify "$ROOT"; then
|
||||
git rev-parse "$ROOT" > "$TOP_LEVEL_DIRECTORY/.git/refs/heads/$ROOT"
|
||||
else
|
||||
(git fsck --lost-found &> /dev/null; git checkout "$ROOT") || die "No HEAD ref available"
|
||||
fi
|
||||
ROOT_GUESS=master
|
||||
|
||||
if [[ -n $(git show-ref refs/heads/main) && -z $(git show-ref refs/heads/master) ]]; then
|
||||
ROOT_GUESS=main
|
||||
fi
|
||||
|
||||
ROOT=${2:-$ROOT_GUESS}
|
||||
|
||||
# Recover the root HEAD if it is missing or corrupt (e.g. master head reads "master")
|
||||
recover_root () {
|
||||
ROOT_HEAD_FILE="$TOP_LEVEL_DIRECTORY/.git/refs/heads/$ROOT"
|
||||
|
||||
if [[ -e "$ROOT_HEAD_FILE" ]]; then
|
||||
if [[ $(cat "$ROOT_HEAD_FILE") = $(echo $ROOT) ]]; then
|
||||
CORRUPT_ROOT_HEAD=true
|
||||
fi
|
||||
else
|
||||
MISSING_ROOT_HEAD=true
|
||||
fi
|
||||
|
||||
if [[ "$CORRUPT_ROOT_HEAD" = "true" || "$MISSING_ROOT_HEAD" = "true" ]]; then
|
||||
ERR="failed to recover $ROOT HEAD"
|
||||
RECOVERED_ROOT_HEAD=$(cat "$TOP_LEVEL_DIRECTORY/.git/logs/refs/heads/$ROOT" | tail -n1 | cut -d' ' -f2)
|
||||
echo "$RECOVERED_ROOT_HEAD" > "$ROOT_HEAD_FILE"
|
||||
say "Recovered $ROOT HEAD, set to $RECOVERED_ROOT_HEAD"
|
||||
CORRUPT_ROOT_HEAD=false
|
||||
MISSING_ROOT_HEAD=false
|
||||
fi
|
||||
}
|
||||
|
||||
recover_root
|
||||
|
||||
LAST_WORKING_DIRECTORY="$(pwd)"
|
||||
cd "$TOP_LEVEL_DIRECTORY"
|
||||
|
||||
ERR="could not get current commit"
|
||||
CURRENT=$(git rev-parse --abbrev-ref HEAD)
|
||||
ERR=""
|
||||
@@ -192,7 +217,6 @@ if [[ -f $FRESH_IGNORE ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
STASH_STAMP=git-fresh-$(date +%s)
|
||||
|
||||
# Stash changed files
|
||||
@@ -303,6 +327,7 @@ if [[ ! -z $(git rev-parse --verify --quiet "$CURRENT") ]]; then
|
||||
if [[ "$ROOT" != "$CURRENT" ]]; then
|
||||
ERR="could not check out $CURRENT branch"
|
||||
git checkout $CURRENT
|
||||
recover_root
|
||||
fi
|
||||
|
||||
if [ "$REBASE" = true ] && [ "$MERGE" = true ]; then
|
||||
@@ -363,4 +388,12 @@ if ! git gc --auto --force; then
|
||||
rm -rf "$TOP_LEVEL_DIRECTORY/.git/gc.log"
|
||||
fi
|
||||
|
||||
if [[ -d "$LAST_WORKING_DIRECTORY" ]]; then
|
||||
cd "$LAST_WORKING_DIRECTORY"
|
||||
else
|
||||
say "Previous working directory does not exist on the branch $ROOT"
|
||||
fi
|
||||
|
||||
recover_root
|
||||
|
||||
ERR=""
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ stash changes
|
||||
prune \fIremote\fP branches
|
||||
.PP
|
||||
\fBgit-fresh\fP will ignore any branches listed in a .freshignore file.
|
||||
.freshignore should contain branch names you would like to ignore
|
||||
\ .freshignore should contain branch names you would like to ignore
|
||||
on separate lines. The file can exist in the current Git repo
|
||||
or in the home directory, i.e. ~/.freshignore.
|
||||
.PP
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "git-fresh",
|
||||
"version": "1.12.0",
|
||||
"version": "1.13.0",
|
||||
"description": "Utility to keep Git repositories fresh",
|
||||
"global": true,
|
||||
"repo": "imsky/git-fresh",
|
||||
|
||||
Reference in New Issue
Block a user