Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions modules/scripts/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{ ... }:
let
entries = builtins.readDir ./.;
dirs = builtins.filter (name: entries.${name} == "directory") (builtins.attrNames entries);
in
{
imports = [
./switch-branch-with-refresh.nix
./nix-init-env.nix
];
imports = map (d: ./. + "/${d}") dirs;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
pkgs.jq
pkgs.coreutils
];
text = builtins.readFile ./nix-init-env.sh;
text = builtins.readFile ./script.sh;
})
];
}
File renamed without changes.
44 changes: 0 additions & 44 deletions modules/scripts/switch-branch-with-refresh.nix

This file was deleted.

10 changes: 10 additions & 0 deletions modules/scripts/switch-branch-with-refresh/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{ pkgs, ... }:
{
home.packages = [
(pkgs.writeShellApplication {
name = "switch-branch-with-refresh";
runtimeInputs = [ pkgs.git ];
text = builtins.readFile ./script.sh;
})
];
}
35 changes: 35 additions & 0 deletions modules/scripts/switch-branch-with-refresh/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

if [ -z "${1:-}" ]; then
echo "Usage: switch-branch-with-refresh <new-branch-name>" >&2
exit 1
fi

current_branch=$(git branch --show-current)

if [ -z "$current_branch" ]; then
echo "Error: Not on a branch (detached HEAD?)" >&2
exit 1
fi

# 新ブランチを作成(現在のコミットをそのまま引き継ぐ)
if ! git switch -c "$1"; then
echo "Error: Failed to create branch '$1'." >&2
exit 1
fi

# 元ブランチをリモートの状態にリセット
git fetch origin
git switch "$current_branch"
echo "Warning: This will reset '$current_branch' to origin/$current_branch with --hard."
read -r -p "Continue? [y/N] " confirm
if [ "$confirm" != "y" ] && [ "$confirm" != "Y" ]; then
echo "Aborted. Switching back to '$1'."
git switch "$1"
exit 1
fi
git reset --hard "origin/$current_branch"

# 新ブランチに移動して完了
git switch "$1"
echo "Done. Commits are on '$1'. '$current_branch' reset to origin/$current_branch."
Loading