Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Sudhanshu Sane
VTK-m
Commits
569655c4
Commit
569655c4
authored
Jun 07, 2017
by
Robert Maynard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add autostash command flag to git-gitlab-sync
parent
0f171de1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
Utilities/GitSetup/git-gitlab-sync
Utilities/GitSetup/git-gitlab-sync
+47
-0
No files found.
Utilities/GitSetup/git-gitlab-sync
View file @
569655c4
...
...
@@ -21,6 +21,10 @@ OPTIONS
--dry-run
Show what would be changed without actually updating
--autostash
automatically stash/stash pop before and after
'
OPTIONS_SPEC
=
SUBDIRECTORY_OK
=
Yes
...
...
@@ -32,15 +36,19 @@ egrep-q() {
# Load the project configuration.
require_work_tree_exists
state_dir
=
"
$GIT_DIR
"
/gitlab-sync
#-----------------------------------------------------------------------------
remote
=
''
autostash
=
"
$(
git config
--bool
gitlab.sync.autostash
||
echo false
)
"
dry_run
=
false
# Parse the command line options.
while
test
$#
!=
0
;
do
case
"
$1
"
in
--autostash
)
autostash
=
true
;;
--no-autostash
)
autostash
=
false
;;
--dry-run
)
dry_run
=
true
;;
--
)
shift
;
break
;;
-
*
)
usage
;;
...
...
@@ -61,6 +69,44 @@ if test -z "$topic" -o "$topic" = "master"; then
fi
#-----------------------------------------------------------------------------
apply_autostash
()
{
if
test
-f
"
$state_dir
/autostash"
then
stash_sha1
=
$(
cat
"
$state_dir
/autostash"
)
if
git stash apply
$stash_sha1
2>&1
>
/dev/null
then
gettext
'Applied autostash.'
else
git stash store
-m
"autostash"
-q
$stash_sha1
||
die
"
$(
eval_gettext
"Cannot store
\$
stash_sha1"
)
"
gettext
'Applying autostash resulted in conflicts.
Your changes are safe in the stash.
You can run "git stash pop" or "git stash drop" at any time.
'
fi
fi
}
finish_sync
()
{
apply_autostash
&&
{
git gc
--auto
||
true
;
}
&&
rm
-rf
"
$state_dir
"
}
#-----------------------------------------------------------------------------
if
test
"
$autostash
"
=
true
&&
!
(
require_clean_work_tree
)
2>/dev/null
then
gettext
'trying to stash local changes'
&&
stash_sha1
=
$(
git stash create
"autostash"
)
||
die
"
$(
gettext
'Cannot autostash'
)
"
mkdir
-p
"
$state_dir
"
&&
echo
$stash_sha1
>
"
$state_dir
/autostash"
&&
stash_abbrev
=
$(
git rev-parse
--short
$stash_sha1
)
&&
echo
"
$(
eval_gettext
'Created autostash: $stash_abbrev'
)
"
&&
git reset
--hard
fi
require_clean_work_tree
"sync"
"
$(
gettext
"Error syncing
\
We are trying to overwrite all local changes on this branch with the version on
\
...
...
@@ -84,5 +130,6 @@ then
fi
fi
finish_sync
# Reproduce the push exit code.
exit
$fetch_exit
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment