Skip to content

Commit 470d560

Browse files
committed
Add --no-stash-ignored / -ni flag to "gl switch".
1 parent 9eccf3c commit 470d560

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

gitless/cli/gl_switch.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def parser(subparsers, _):
2121
help='move uncomitted changes made in the current branch to the '
2222
'destination branch',
2323
action='store_true')
24+
switch_parser.add_argument('-ni', '--no-stash-ignored',
25+
help='do not stash ignored files, has no effect if --move-over is also set',
26+
action='store_true')
2427
switch_parser.set_defaults(func=main)
2528

2629

@@ -33,6 +36,6 @@ def main(args, repo):
3336
pprint.err_exp('to create a new branch do gl branch -c {0}'.format(args.branch))
3437
return False
3538

36-
repo.switch_current_branch(b, move_over=args.move_over)
39+
repo.switch_current_branch(b, move_over=args.move_over, no_stash_ignored=args.no_stash_ignored)
3740
pprint.ok('Switched to branch {0}'.format(args.branch))
3841
return True

gitless/core.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,16 @@ def listall_branches(self):
256256
"""
257257
return self.git_repo.listall_branches(pygit2.GIT_BRANCH_LOCAL)
258258

259-
def switch_current_branch(self, dst_b, move_over=False):
259+
def switch_current_branch(self, dst_b, move_over=False, no_stash_ignored=False):
260260
"""Switches to the given branch.
261261
262262
Args:
263263
dst_b: the destination branch.
264264
move_over: if True, then uncommitted changes made in the current branch are
265265
moved to the destination branch (defaults to False).
266+
no_stash_ignored: if move_over is False and no_stash_ignored is True, then
267+
stash only non-ignored files. If both move_over and
268+
no_stash_ignored are False, then stash all files, including ignored files.
266269
"""
267270
if dst_b.is_current:
268271
raise ValueError(
@@ -346,7 +349,10 @@ def save(b):
346349

347350
if not move_over:
348351
# Stash
349-
git.stash.save('--all', '--', msg)
352+
if no_stash_ignored:
353+
git.stash.save('--include-untracked', '--', msg)
354+
else:
355+
git.stash.save('--all', '--', msg)
350356

351357
def restore(b):
352358
s_id, msg = _stash(_stash_msg(b.branch_name))

0 commit comments

Comments
 (0)