11 Commits

Author SHA1 Message Date
Ivan Malopinsky 7d0d33d32b Merge pull request #93 from imsky/main
Add support for main branch as root
2020-10-27 19:24:51 -04:00
Ivan Malopinsky b2fd270558 1.13.0 2020-10-27 19:23:55 -04:00
Ivan Malopinsky 3d7177e84c if only main branch exists, use that as root 2020-10-27 19:22:46 -04:00
Ivan Malopinsky 8bbe2a7d49 Merge pull request #92 from hrishabh23/ppwd
Change dir to repo root before making changes
2019-10-12 14:50:53 -04:00
Hrishabh 136a777d73 Change dir to repo root before making changes 2019-10-12 01:34:54 +05:30
Ivan Malopinsky 9dd178ded8 1.12.1 2019-06-23 20:07:35 -04:00
Ivan Malopinsky 6ad55433df use correct commit from log for root recovery 2019-05-27 15:54:48 -04:00
Ivan Malopinsky cf050df1f6 fix recovery logic, recover root before getting current commit 2019-05-27 15:39:44 -04:00
Ivan Malopinsky 074154e726 add root HEAD recovery function 2019-05-27 15:30:07 -04:00
Ivan Malopinsky 900e9120b5 update LICENSE years 2019-01-21 18:09:47 -05:00
Ivan Malopinsky 8b0bc89eb8 minor tweaks to get around groff treating leading . as a special character 2019-01-21 18:08:56 -05:00
4 changed files with 47 additions and 14 deletions
+1 -1
View File
@@ -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
+44 -11
View File
@@ -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
View File
@@ -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
View File
@@ -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",